Math Latex horizontally aligned with text - latex

So I am using the flashcard software Anki which uses LaTex for its math equation formatting
So when I write an equation with a fraction in the same line as standard text, it automatically allignts the lowest point of the equation, in the case the denomitor of the fraction, with the bottom the normal text. How can I get the equation and text to be horizontally aligned.
Some text before an equation: [$]\frac{x^2}{y}[/$]

What I did was to make the equation itself a bit smaller to better match the text around it.
To add it for all equations go to: Tools > Manage Note Types > Options > Header
Or you could place it inline: [$]\tiny[/$]
An excellent writeup on sizing text this way can be found at tex.stackexchange
And you may be able to get better results by changing the font itself.

As the LaTeX snippets are finally rendered as images, this is a CSS issue. The equations become centered when you add the following rule to your card CSS:
img[src*="latex"] {
vertical-align: middle;
}
This CSS rule matches all images whose file name contains the string latex and centers them in their respective line of text. It thus matches all anki-generated latex images.
If needed, I can supply info on how to edit the card CSS or on how to make Anki and Latex work together.

Related

MathJax Font Size

In MathJax, I am able to adjust the font size using the answer here (i.e. shown below). Is there a way to adjust the font size of the normal text too without dollar signs around it too? For example, when I type the following: Let $f(x)=x^2$.
The text size around the word "Let" would be small and $f(x)=x^2$ would be much larger. I want to scale the text of the words as well, and I am not sure how to do so.
chtml: {scale: 1.5},
svg: {scale: 1.5},
In regular Latex, you could do Let $f(x)=x^2$.
However remember that, as the name suggests, MathJax doesn't aim to make all of Latex available to the web but focuses on the math part of Latex (and also AsciiMath and MathML of course). A key thing to remember here is that MathJax actually uses the math delimiters to find where there are content to typeset and when you do Let $f(x)=x^2$, MathJax doesn't do anything about the Let since it is outside the math delimiters.
Nonetheless, there are ways to use regular text in Latex math mode too. For example by means of \text{} so in your case, you could accomplish what you want with $\text{Let } f(x)=x^2$
Now, simply setting the text size of the surrounding content will make all of the Latex bigger:
<p style="font-size: 1.5em;">$\text{Let } f(x)=x^2$</p>
<p style="font-size: 2.5em;">$\text{Let } f(x)=x^2$</p>
<p style="font-size: 5em;">$\text{Let } f(x)=x^2$</p>
If you want a bigger horizontal space between the math and the Let, you can add a horizontal spacer:
<p>$\text{Let}\hspace{2mm} f(x)=x^2$</p>
I have prepared a sandbox which you can play around with, also try to uncomment the scale part of the configuration to see this factor in play (however, I usually use font height and not scale to control size): Sandbox
Some things to remember:
Example uses MathJax 3, there might be small differences in comparison to version 2.
Example uses the HTML output processor (as in your example), if you load a different MathJax script, you might be outputting svgs instead and then some options won't have impact, so always check these things thoroughly when something doesn't work.
$...$ is not a standard pair of delimiters so it has to be explicitly configured, otherwise MathJax won't recognize it as inline Latex math.
MathJax automatically does one round of initial typesetting, if you want to update content dynamically, you have to explicitly instruct MathJax to typeset again.
Good luck!

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.

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.

Character spacing in LaTeX with lstlisting package

I'm trying to get my code snippets to look as good as possible and so far I'm having troubles with the character spacing. Here is an example of the output:
alt text http://grab.by/grabs/2bb230de7c088d007733f52b95a40363.png
While the text in small is perfect, all the keywords that are in capital letters look terrible. Here are the settings I use
\lstset{basicstyle=\footnotesize, basewidth=0.5em}
If I increase the basewidth, the capital letters look good, but I can't get any decent sized line of code in one line. The following example does not fit in a page and I already put two line breaks in:
alt text http://grab.by/grabs/97ec29aa5a6811ce28bcd30bd389b52f.png
Does anyone have a clue how I can get this to work? Using \ttfamily does the trick, however, I'd prefer keeping the font.
Thanks.
If you prioritize looking nice, then using flexible colums is preferable:
\lstset{basicstyle=\footnotesize, columns=fullflexible}
You "obviously" need to scale the capital letters down horizontally. I do not know of a way to do this without actually editing the font itself.
However, you could put the entire listing into a \scalebox resp. \resizebox (from the graphicx package).
On a side note, the font you are using seems a bit strange, though, since the distance between small letters is significantly bigger than that between capital letters.

Resources