I am working on a .md file which includes latex. The file looks like this:
$$
1+1 = 2
\\
2+2 = 4
$$
The File:
When viewing it as markdown the file looks perfectly fine with the new line properly added.
Although when I use pandoc to write the file to a pdf the following happens:
PDF File (from pandoc)
As you can see the new line has been completely removed and makes the latex hard to read.
I am using the following pandoc command:
pandoc --wrap=preserve in.md -o out.pdf
The --wrap=preserve does not seem to be working as it ignores a new line. I have also tried to use \newline \linebreak instead of \\ and neither seem to be working.
How can I specify a line break so pandoc will make sure to keep the breaks rather than keeping everything inline?
Whatever file preview tool you are using: it is lying to you. Double-backslash is not the correct way to insert newlines into math.
Pandoc either parses the math and converts it into the target format, or just passes the code through, depending on the output format. For PDF output via LaTeX, the equation is just passed through. (You can check by running pandoc with --verbose, which, among other things, will print the generated raw LaTeX code.) So it is clear that the problem lies with the input.
There are multiple ways to add linebreaks into math in LaTeX. One of them is the align* environment:
\begin{align*}
1+1 = 2
\\
2+2 = 4
\end{align*}
This will give you the expected PDF output, but has the downside of not showing up in other output formats like HTML. I'm not aware of any method which would produce linebreaks in math equations across all possible pandoc output formats. You'll have to use multiple single-line equations if you need that.
Texinfo adds macros starting with '#'. I'm curious how to do that in plain TeX because I'm trying to create a simple TeX framework for my friends' needs and it would be more readable for them.
texinfo essentially replaces plain TeX's backslash with the at sign. This is done by setting the so-called \catcode of the at sign to 0.
Note that with this setting, #command means exactly the same as \command, you don't get a second family of command names.
Note also that designing and implementing a new TeX format is a lot of work; it is much easier to resort to one of the existing TeX formats.
E.g., I have this Markdown cell that use the sanctioned way of using a LaTeX macro in the notebook
$\def\abc{a\,b\,c}$ The first three letters are $\abc$.
and I have what I want in the notebook. OTOH, when I "Download as PDF via LaTeX"
the conversion process fails with these errors in the standard error of the console
! Undefined control sequence.
l.229 ...c{a\,b\,c}\) The first letters are \(\abc
\).
?
! Emergency stop.
l.229 ...c{a\,b\,c}\) The first letters are \(\abc
\).
! ==> Fatal error occurred, no output PDF file produce
Transcript written on notebook.log.
because Latex itself doesn't accept a definition embedded in a mathematical expression. Because Markdown doesn't accept these definitions outside a mathematical expression I feel like I'm trapped in a Comma 22 situation.
I'm pretty sure the system can be fooled using Raw NBconvert cells and smart latex code but I'm missing some step in my head... Any help will be properly appreciated, ciao
The definition is accepted in the mathematics, but in TeX, definitions are localized to the nearest enclosing group. Math delimiters are enclosing groups, so the definition is remove after the math. Try using \gdef instead of \def to get a global definition. This will require that you load the begingroup extension in MathJax, so you will have to add that to the configuration (I don't know how that is done in IPython, though).
I recently discovered reST/Sphinx and tried to use it to document a python class I had written some time before.
After some experimentation I found out I needed to write :math:`K_\\alpha` to get the greek letter in the subscript while using the make latexpdf target. With a single \ there were errors. Strangely enough every other greek letter only needed a single \ to produce the desired output.
What is happening?
Thank you so much for asking this. It finally helped me solve my related problem.
For me, \alpha and \beta both fail.
They both fail even without the subscript part coming into play. But if I use the curly braces it works:
:math:`\alpha`
does not compile
:math:`{\alpha}`
gives me the symbol I want
:math:`{\\alpha}`
gives me the word 'alpha' written as adjacent math variables a, l, p, h, a.
To get a K followed by a subscripted α in inline text, use
:math:`K_{\alpha}`
Note curly braces and backticks. It works fine and is what you would expect based on these references:
http://www.emerson.emory.edu/services/latex/latex_117.html
http://sphinx-doc.org/ext/math.html#role-math
In math markup used in Python docstrings, you need two backslashes (or use "raw" strings):
:math:`K_{\\alpha}`
Edit: I was wrong about the curly braces. It turns out that these two samples give the same result in the PDF output:
:math:`K_{\alpha}`
and
:math:`K_\alpha`
What is happening?
\a is interpreted as a control character ("bell", just like e.g. \n "end of line"). Notably, \b (backspace) could be a control character as well, but is for some reason not interpreted as such.
Note that another possible workaround is using raw strings (r"""some text"""), as noted also in the sphinx math documentation 2.
Sources: Wikipedia, Sphinx documentation, "Math support in Sphinx"
Following the previous questions on this topic, when you produce a website in LaTeX what is the best way to produce a url that contains a tilde? \verb produces the upper tilde that does not read well, and $\sim$ does not copy/pase well (adding a space when I do it). Solutions?
It seems like this should be one of those things that has a very easy fix... if it doesn't, why not?
I'd look at the url package.
I know this is an old question, but I recently came up with something that, despite a severe lack of elegance, works beautifully.
\catcode`~=11 % make LaTeX treat tilde (~) like a normal character
\newcommand{\urltilde}{\kern -.15em\lower .7ex\hbox{~}\kern .04em}
\catcode`~=13 % revert back to treating tilde (~) as an active character
Now you can use \urltilde inside of a \url tag (even in a .bib file) and:
1) the URL will render perfectly;
2) clicking on the URL will take you to the correct address; and,
3) copy-paste will put the correct address in the clipboard.
This is the only solution I have found that satisfies all three of these requirements. I hope it helps somebody out there.
url package didn't work for me. hyperref does the job.
\usepackage{hyperref}
\url{http://website.com/~username/some_stuff/}
I think it is better to use URL encoding in such a case (see, e.g., http://www.blooberry.com/indexdot/html/topics/urlencoding.htm).
It means replacing the tilde in the link with %7E.
Maybe it does not look so good in the final document (readers will see %7E instead of the tilde), but at least the copy-paste functionality works for sure, which I think is the most important thing.
For instance, for the link www.example.com/~someuser/somepage.htm I use the following code:
{\tt http://www.example.com/\%7Esomeuser/somepage.htm}
PS: The same applies for all links with white spaces or any other special characters.
I think $_{\widetilde{~}}$ works good for the tilde issue.
I want to suggest using %7e
\tt{http://example.com/\%7etest}
tt is for making it monospace.
It looks a bit different, but it allows copy-and-paste.
\symbol{126} would be another way, but in the default font it also yields a superscripted tilde. An ugly hack (but what isn't in LaTeX) would be to use
${}_{\textrm{\symbol{126}}}$
which produces a text tilde in Math mode and subscripts it. So it appears in the middle of the line. Seems to work for a clickable link as well. You can always put that into a command on its own :)
I'm not a latex user admittedly, but does this page help?
http://www.cse.wustl.edu/~mgeorg/html/tildalatex.html
They do the following:
\def\urltilda{\kern -.15em\lower .7ex\hbox{\~{}}\kern .04em}
\def\urldot{\kern -.10em.\kern -.10em}
\def\urlhttp{http\kern -.10em\lower -.1ex\hbox{:}\kern -.12em\lower 0ex\hbox{/}\kern -.18em\lower 0ex\hbox{/}}
The way this is used is
{\tt mgeorg#cse\urldot wustl\urldot edu}
{\tt \urlhttp www\urldot cse\urldot wustl\urldot edu/\urltilda mgeorg}
After wasting a lot of time on a related problem with LaTeXing a tilde, I thought I should record my results here in case it is a help to anyone else.
tldr: To avoid some of the difficulties of typesetting a proper tilde ~ character, I recommend adding
\usepackage[T1]{fontenc}
in the preamble of your latex file to get more modern versions of font encoding. On modern TeX installations, this automatically loads the T1-encoded version of Knuth's Computer Modern fonts.
Details:
As has been noted by previous posters, using standard pdflatex/latex with the default fonts (the original OT1-encoded Computer Modern), there are difficulties in trying to render a regular tilde character, ~, and there are various workarounds with varying degrees of satisfaction. One workaround is to use the textasciitilde command. For example, you can use it to put a tilde in a URL, like:
https://w3.pppl.gov/\textasciitilde{}hammett
This gives a raised tilde (the kind of tilde intended for accents over another character), and methods to lower it to a more normal tilde are discussed by other posters. While this works as expected if the resulting PDF file is viewed in Adobe Acrobat, a downside is that if the PDF is viewed with the built-in Preview app on a Mac (or if viewed in TeXShop's previewer, which uses the same Mac libraries for rendering), then this URL link visually looks correct as https://w3.pppl.gov/~hammett, but if you actually click on it, it gets interpreted only as
https://w3.pppl.gov/
If you try to cut and paste the whole URL from Preview into a browser, the tilde in the pdf is replaced with a blank
https://w3.pppl.gov/%20hammett
so it doesn't work. (If you paste into some browsers, there are other special characters added also). (The \url{...} command will display a URL with tildes correctly, but forces it to use a fixed-space terminal font, and there are times when you want to use a tilde somewhere besides in a URL.)
Investigating further, I learned that the character that latex puts into the pdf file is not a regular tilde character but a "Combining Tilde"
COMBINING TILDE Unicode: U+0303, UTF-8: CC 83
(previously known as a "non-spacing tilde", indicating its usage for accents over another character) and that is what Mac's Preview renders. This means that cut-and-paste from Mac's Preview into a browser fails.
However, Adobe Acrobat somehow implemented a workaround and when displaying the pdf converts this into a regular "Tilde"
TILDE Unicode: U+007E, UTF-8: 7E
so cut-and-paste of a URL with a tilde from an Adobe-displayed pdf file into a web browser works fine.
(I determined these unicode values by copying the rendered tilde character from the TeXShop Preview window and pasting it into the Character Viewer app in the menu bar on a Mac. Then right-click on the character to select "Copy Character Info". The Character Viewer app can be turned on in Mac Preferences, Keyboard, and select "Show keyboard and emoji viewers in menu bar".)
This problem goes away if you use T1-encoded fonts by adding
\usepackage[T1]{fontenc}
to your latex file preamble. Furthermore, if you use the Adobe Times-like font
\usepackage{newtxtext}
then tilde is rendered at mid height automatically and doesn't need to be lowered. (The above command uses the newtx font only for regular text, while leaving the math fonts unchanged. I like newtxtext because it is slightly darker than CM. But for math I prefer to keep Knuth's traditional Computer Modern CM font, because the newtxmath font, like other Times math fonts, renders math italic v in way that is confusingly like a Greek nu.)
P.S.: For more info on why it's always good to use the fontenc package for a more modern approach than the 1970's original encoding, see (1) https://www.texfaq.org/FAQ-why-inp-font, (2) https://tex.stackexchange.com/questions/664/why-should-i-use-usepackaget1fontenc, and (3) https://en.wikibooks.org/wiki/LaTeX/Fonts.