Copying LaTeX from Mathematica - latex

Is there a way to copy text with InlineFormula styles to the clipboard with the math section within the dollar signs?
Take this for example. The following screenshot shows part of a mathematica notebook:
I have duplicated the same cell to show the expression form. Now, when I right click on the text and click copy as LaTeX and paste it say here:
\text{I hope this inline text is copied within the dollar signs: }
f(x) = 3. \text{Did} \text{it} \text{work}?
I get that. If I were to save the file as latex I would obtain something like this:
I hope this inline text is copied within the dollar signs: \(f(x) = 3\). Did it work?
I have never used \( \) in latex. But I'm assuming this is another form of doing inline math since it worked when I compiled it with LaTeX
Sometimes I find myself typing some text in Mathematica and later pasting some text with inline text into some latex file. Is there some settings I can change so that I can obtain the inline math mode instead of the \text{} command?
Another related question is, Is it possible to do display math in Latex? The DisplayFormula style doesn't seem to work quite right.
Any knowledge about latex settings in Mathematica is welcome.

Related

Customizing Body Text and Images using Markdown, Pandoc, Beamer to create PDF Slideshows

I have a series of markdown files that I am turning into slides using Pandoc and the Beamer template. I am creating my own custom Beamer template in order to format those slides.
pandoc --slide-level 2 -fmarkdown-implicit_figures -t beamer --template mytemplate.beamer -o test.pdf *.md
I am struggling with making certain elements look the way I would like them to.
My simplified markdown looks like this:
## Header
Normal Body Text
![Image](images/Image1.png "Image")
Specifically, my images are coming out left justified. I can't figure out how to get them to center. If I remove the -fmarkdown-implicit_figures option, then the images are properly centered, but includes captions that I don't want. Adding that flag eliminates the captions but also eliminates the centering.
At the same time, I want the normal body text to be centered as well. So in the above example I would like the text Normal Body Text to be centered. Again, I can't figure out how to do that. I have managed to center other elements (such as the header), but I can't find an appropriate name for the element that represents normal body text.
Can anyone offer a solution to either of these issues?
I found a way to center the images. It may not be the best option, but this seems to work:
\usepackage{letltxmacro}
% Save the meaning of \includegraphics
\LetLtxMacro\latexincludegraphics\includegraphics
% Update the include graphics command to include centering
\renewcommand{\includegraphics}[2][]{%
\centering
\latexincludegraphics[#1]{#2}}
To ensure the normal text was centered, I used the following, again I am unsure if this is the best way:
% Center Text By Default
\usepackage{ragged2e}
\centering

How to label boxed text in markdown?

My question in short is: How can you create a boxed text with a label that can be referenced?
Background: I am generating LaTeX output from a Markdown document to be included in a larger LaTeX document. I would like to describe the steps of an algorithm as boxed text with a label that can be referenced. I know how to create a labeled figure and how to create boxed text, but I haven't been able to figure out how to combine the two, i.e. how to label the boxed text as if it was a figure, or how to include the text in a figure (other than converting it to an image, which I'd like to avoid).
An initial "solution": Just putting a the box and an empty figure next to each other (see below) kind of works, except that nothing ensures that the figure label won't float away from the box as I work on the document, since figures are floating objects while text boxes are part of the text, and the two are handled differently by LaTeX. Moreover, you may need to use LaTeX vertical space commands to make it look reasonably good, but it is hard to get it perfect. Is there a simple solution? Thanks!
P.S. I know that I could just switch to LaTeX and figure out a solution there, but here I am looking for a solution in Markdown, possibly making use of some embedded LaTeX commands.
You can see the algorithm in Figure \ref{methods:estimating}.
\fbox{\parbox{5in}{
1. Initialize $b_r=0$ for $r=1..R$ \\
2. For each item $i, i=1..U$, calculate ... \\
3. Re-estimate ... \\
4. Proceed to Step 2 until it converges.
}}
![Estimating ... \label{methods:estimating}]()
It is rendered like this:
You can use one of the packages for writing algorithms. See https://www.sharelatex.com/learn/algorithms.

figure caption centering in nbconvert?

I have cells underneath figures in an ipython notebook that contain figure caption text. I would like them to be centre('center')-aligned. I use "< center >" in the markdown, which gives exactly the appearance I'm after in the notebook. But when nb-converting to latex, the text gets shunted over to the left.
So is there a way to get nbconvert to recognize text alignment in markdown cells when converting to latex?
Thanks.
You have actually asked two different questions:
is there a way to get nbconvert to recognize text alignment in markdown cells
figure caption (centering) in nbconvert
ad 1)
To convert the markdown to latex pandoc is used. Unfortunately, pandoc removes raw html from markdown if converted to latex (if also removes raw latex when converting markdown to html).
So it is not that straight forward to use html tags to format the output in both html and latex. This formatting may be achieved based cell metadata but that is not that trivial currently.
ad 2)
Nevertheless it is possible to create caption like text to work with html and latex.
Here we have to distinguish between caption for pyout or stream data (e.g. Ipython.display.Image) and markdown images.
pyout and stream
A possible approach is to create a Caption class like
class Caption():
def __init__(self,s):
self.s = s
def _repr_html_(self):
return '<center>{0}</center>'.format(self.s)
def _repr_latex_(self):
return '\\begin{center}\n'+self.s+'\n\\end{center}'
which is called after the image. Note that both should be called with the IPython.display.display method, e.g as oneliner
display(Image('image.jpg'),Caption('Figure Caption'))
This approach allows process the captiontext with python, e.g. to add figure numbers.
If you want to add such a caption to a matplotlib plot, it is a bit more tricky as the wrong ordering has to be overcome. A possible approach is to plot using this snippet
%matplotlib inline
plt.plot([1,2])
f=plt.gcf()
plt.close()
display(f,Caption('Plot'))
It may be noted the the default latex template of IPython 1.x doesn't play well with this approach, as here, image and caption are only loosely coupled and thus, vertical space might be included during latex compiling. The latex_basic template works much better. In IPython master the default templates are working fine.
markdown images
Markdown allows to use images like
![Caption](/files/image)
When converting to latex pandoc can take the Caption part and create a real latex caption.
Similar, when converting to html the caption gets embedded in a caption class to be easily styleable using css.
However, currently IPython requires a "/files/" prefix which is currently not removed, thus the image file won't be found by latex. (Fixed by now)
Be aware that these markdown image calls do not embed but only link the image into the ipynb file, therefore, the image has to remain available.

Mathematica's spacing of symbol accents when typesetting mathematical formulas

Mathematica appears to have difficulty horizontally aligning accents (e.g. bars, hats, and tildes) when placed on top of certain mathematical symbols.
Here's a simple example:
Using the AdjustmentBox typesetting construct (or Alt-Left/Right arrow in the frontend), one can manually adjust the relative horizontal position of the hat and the symbol j to produce the more aesthetically pleasing:
There are two problems here:
1). It is inconvenient and time-consuming to make these manual adjustments when this should really be the job of the typesetting engine proper. Indeed, LaTeX is able to position accents correctly over all of the standard symbols (roman and greek letter forms) without the need to manually tweak their relative positioning.
2). The relative re-positioning of the symbols using AdjustmentBox is lost when exporting the Notebook to PDF for printing and re-distribution.
Question:
Does anyone have any suggestions for a more convenient way (preferably automatic) to improve the typeset quality of formulas in Mathematica notebooks that use accents, that preferably will also survive export of the notebook document to PDF format before printing?
You can select " ĵ " from the Windows character map and paste it in.
Style[ĵ, Italic, 24, Bold, FontFamily -> "Times"]
Also you can assign it to an input alias (borrowing from Andrew Moylan)
n = SelectedNotebook[];
SetOptions[n,
InputAliases ->
Append[Options[n, InputAliases][[1, 2]], "j^" -> "ĵ"]]
Typing Escj^Esc produces ĵ.
Well, I do not think that this is possible.
You may ask Wolfram Research to include unicode character 0135 , i.e., they should add \[JHat], like
\[IHat]. Then italics display nicely.

Latex color box inline with text

I'm trying to put together a LaTeX color box. The xcolor package \fcolorbox seem to be what I want, but I can't get the rendering quite correct. When I use
\fcolorbox{black}{red}{}
it renders a small box sunken to the bottom of the text line. The best I've managed to do is to fake it with a similar text color:
\fcolorbox{black}{red}{\textcolor{red}{--}}
However, I'm worried that this won't render correctly in all situations with defined colors. Is there a way I can declare an empty text box with full in-line text height? Is there another solution?
I'm basically looking for the code that produces the color boxes all through the document at ftp://ftp.dante.de/pub/tex/macros/latex/contrib/xcolor/xcolor.pdf. The boxes I'm referring to are used throughout, but the first instance is on page 4. Thanks.
The xcolor.dtx file in the same directory as the pdf contains the source for the package and the source for the documentation. The relevant bits from the source for the documentation:
\def\testclr#1#{\#testclr{#1}}
\def\#testclr#1#2{{\fboxsep\z#\fbox{\colorbox#1{#2}{\phantom{XX}}}}}
...
(Answer: 40\% \testclr{green} $+$ 60\% \testclr{yellow} $=$ \testclr{green!40!yellow}, e.g., |\color{green!40!yellow}|)
Basically, use \phantom{} on the contents of your color box, and make sure that at least one of the phantom characters is full-height.
Also, https://tex.stackexchange.com/

Resources