Single spacing in Jupyter math mode - latex

I'm trying to write out a series of math equations inline in Jupyter. I've written the following in my markdown:
Solution:
$x_1 = -8$
$x_2 = 3$
The problem is that this displays much like it does in StackOverflow, with a space in between. Is there a way to display those as a single-spaced entity, rather than double-spaced? I'd rather them be left-aligned, so I don't want to double up the $$.

You can use a <br /> tag to insert a line break between the two equations (less space between lines):
Solution:
$x_1 = -8$ <br />
$x_2 = 3$

Related

How could I get an editor to align vertically by a single character in selected text?

Let's say I've got a document (it happens to be a BibTeX file) filled with thousands of entries like this:
#article{hierarchy_problem_1,
title = {Dynamics of spontaneous symmetry breaking in the Weinberg-Salam theory},
author = {Susskind, Leonard},
journal = {Physical Review D},
volume = {20},
number = {10},
pages = {2619--2625},
year = {1979},
month = {November},
publisher = {American Physical Society}
}
I want to be able to select one of those, or maybe a bunch of them, and get them to change to be aligned vertically by a single character, in this case the "=" character, so it becomes something like this:
#article{hierarchy_problem_1,
title = {Dynamics of spontaneous symmetry breaking in the Weinberg-Salam theory},
author = {Susskind, Leonard},
journal = {Physical Review D},
volume = {20},
number = {10},
pages = {2619--2625},
year = {1979},
month = {November},
publisher = {American Physical Society}
}
My editor of choice is Geany just now (which has the facility to send selected text to some external, custom command -- context menu > Format > Send Selection to) but I will entertain anything. Bearing in mind that some titles of the papers can contain the "=" character, what might be a good way to do this? I would suspect at least that the "=" character in a line after some text like "journal", would be the first instance of that character, and then it gets spaces (I'd prefer to avoid tabs) added before it in order for it to end up at, say, the 30th column. What might be some way to do this?
Maybe a shell/regex expert can build a script used in a custom command.
Personally, in your situation I will :
Set tabulation to <tab> in the document
search & replace = by <tab><tab><tab><…>=
Adjust distance with a vertical selection (need the plugin Extra Selection).
Notepad++ has an align to clipboard character.

Fill line up with special Character before and after Text

I would like to create a Sublime Text 2 Snippet that fills up the space before and after the Variable I type with spaces.
It should look like this:
===========================my_filename.js===========================
The Filename should be centered so the number of spaces before and after the Text have to match.
Also I need the overall column width of this line the stay the same. So when I add 2 Characters the number of spaces on each side gets reduced by one.
I think a sample for this would be:
spacesLeft = roundDown((columnWidth/2) - (textSize/2))
spacesRight = roundUp((columnWidth/2) - (textSize/2))
But since only RegEx is available in Sublime Snippets I don't see me able, to accomplish this task.
Could Vintagmode help me in any Way?
Thanks for your help!
Because snippets are essentially static, they wouldn't be able to help you in this case. However, you could create a plugin to do this relatively easily. Sublime Text uses python for its plugins. You can create one by going to Tools > New Plugin. ST2's API can be found here and is very impressive. Essentially, you'll want to store the current selection (your variable) using
sel_reg = self.view.sel()[0] # the current selection 'Region'
sel = self.view.substr(sel_reg) # the text within the 'Region'
Then generate the ='s
signs = ''
each_side = len(80 - len(sel))/2 # 80 is the standard window length,
# change this to what you want.
# Not sure about how to make it dynamic.
for x in xrange(each_side):
signs += '='
Then replace the current line (self.view.line(sel)) with signs + sel + signs.

counting line numbers of a poem with nokogiri / ruby

I've struggling to try to do this with a simple regex but it's never been very accurate. It doesn't have to be perfect.
Source has a combination of and tags. I don't want to count blank lines.
Old way:
self.words = rendered.gsub(/<p> <\/p>/,'').gsub(/<p><br\s?\/?>|(?:<br\s?\/?>){2,}/,'<br>').scan(/<br>|<br \/>|<p/).size+1
New way (not working:
Tries to turn all the + into paragraphs, then throw it into nokogiri to count paragraph tags with more than 3 chars in them (I have no idea how? Counting 1 letter lines would be nice too, but this worked ok in javascript)
h = rendered
h.gsub!(/<br>\s*<br>/gi,"<p>")
h.gsub!(/<br>/gi,"<p>") if h =~ /<br>\s*<br>/
h.prepend "<p>" if !h =~ /^\s*<p[^>]*>/i
h.replace(/<p>\s*<p>/g,"<p> </p><p>")
Nokogiri::HTML(rendered)
# find+count p tags with at least 1-3 chars?
# this is javascript not ruby, but you get the idea
$('p', c).each(function(i) { // had to trim it to remove whitespaces from start/end.
if ($(this).children('img').length) return; // skip if it's just an image.
if ($.trim($(this).text()).length > 3)
$(this).append("<div class='num'>"+ (n += 1) +"</div>");
})
Other methods are welcome!
Example poem ( http://allpoetry.com/poem/7429983-the_many_endings-by-Kevin )
<p>
from the other side of silence<br>
you met me with change and a pocket<br>
of unhappy apples.</p>
<p>
</p>
<p>
<br>
we bled together to black<br>
and chose the path carefully to<br>
france.<br><br>
sometimes when you smile<br>
your radiant footsteps fall<br>
and all around us is silence:<br>
each dream step is<br>
false but full of such glory</p>
<p>
</p>
<p>
<br>
unhappiness never made a student of you:<br>
just two by two by two. now three<br>
this great we that overflows our<br>
heart-cave<br><br>
each jewel-like addition to the delicate<br>
crown. but flowers fall and dreams,<br>
all dreams, come to and end with death.</p>
Thank you!
For posterity, here's what I'm using now and it seems to be quite accurate. Non latin chars cause some problems sometimes from ckeditor, so I'm stripping them out for now.
html = Nokogiri::HTML(rendered)
text = html.at('body').inner_text rescue nil
return self.words = rendered.gsub(/<p> <\/p>/,'').gsub(/<p><br\s?\/?>|(?:<br\s?\/?>){2,}/,'<br>').scan(/<br>|<br \/>|<p/).size+1 if !text
#bonus points to strip lines entirely non-letter. idk
#d "text is", text.gsub!(/([\x09|\x0D|\t])|(\xc2\xa0){1,}|[^A-z]/u,'')
text.gsub!(/[^A-z\n]/u,'')
#d "text is", text
self.words = text.strip.scan(/(\s*\n\s*)+/).size+1

Ruby-on-Rails: Mixing Sanitize and Truncate can be a dirty thing

So stand alone I get what I need. But I want to truncate it, my dynamic text comes out with dirty text globbered with Microsoft Word garbage.
An Example :
&Lt;! [If Gte Mso 9]>&Lt;Xml> &Lt;Br /> &Lt;O:Office Document Settings> &Lt;Br /> &Lt;O:Allow Png/> &Lt;Br /> &Lt;/O:Off...
So how do I get the best of both worlds? Is there a shorthand ruby way to do this? For example a gsub statement that would clip off everything after the 125th char?
if you just want to slice, you can
>> long_ugly_string = "omg this is a long string"
=> "omg this is a long string"
>> long_ugly_string[10..-1]
=> "s a long string"
Reference: http://ruby-doc.org/core/classes/String.html#M000771
so, you are just specifying the starting character (10) and the ending character (-1 tells it to go to the end of the string).

How to reduce the separation from other text using LaTeX minted?

I want to use the minted package to give me syntax highlighting but it has a spacing of more than a centimeter.
Setting:
\setlength{\parskip}{0pt}
\setlength{\parsep}{0pt}
\setlength{\headsep}{0pt}
\setlength{\topskip}{0pt}
\setlength{\topmargin}{0pt}
\setlength{\topsep}{0pt}
\setlength{\partopsep}{0pt}
does not help at all. Is there any way to reduce the spacing from the rest of the text?
minted internally uses the Verbatim environment from the fancyvrb package. In the documentation of the implementation, the following formula for the spaces is given:
<topskip> = \topsep + \partopsep + \parskip
<botskip> = \topsep + \partopsep
And
Except when in label or after nobreak, \parskip is added with \addvspace, so that net space is:
MAX{\topsep (+\partopsep) + \parskip , \lastskip }
(The usual \#item works the same way.)
Hence, setting \partopsep to some other value does the trick; I’ve tried it, and you need a negative value to remove the margin:
\setlength\partopsep{-\topsep}
This removes most of the space between the text body and the code. To get a distance of 0.5cm, add its distance to that:
\setlength\partopsep{-\topsep}
\addtolength\partopsep{-\parskip}
\addtolength\partopsep{0.5cm}
An implementation can be found in https://tex.stackexchange.com/a/19423
If you want to change the line spacing you can use:
\linespread{1.0}
And play a little bit around with the number in the curly brackets.
The commands you have given as an example refer to the page environment.
See this Wiki for additional explanations and examples.

Resources