MathJax Font Size - 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!

Related

Math Latex horizontally aligned with text

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.

MathJax overarrow too short

I am trying to place an overarrow over a piece of text in MathJax.
I am using a custom font that I declare in the code-
\(\overrightarrow{\style{font-family: mysans, TeX, Arial, sans-serif;}{\text{" + tString + "}}}\)"
It works ok for most letters- for capital W or M , using a couple in a row like "WWW" the overbar is too short.
For lowercase i , using a couple in a row, ie "iii" it is too long. My hunch is that MathJax is using a standard character width size to figure out the length of the overarrow and when the character is much longer or shorter than that size, it calculates the overarrow incorrectly. Is there any way around this?
Thanks!
First off, you generally cannot use custom fonts with MathJax. As the documentation says
Since browsers do not provide APIs to access font metrics, MathJax has to ship with the necessary font data; this font data is generated during development and cannot be generated on the fly. In addition, most fonts do not cover the relevant characters for mathematical layout. Finally, some fonts (e.g. Cambria Math) store important glyphs outside the Unicode range, making them inaccessible to JavaScript.
However, if you are only looking to use custom fonts in text elements, then there is a way to work around this: style the surrounding context and set mtextFontInherit:true for the output jax, cf. e.g. here for HTML-CSS.
Unfortunately, this won't actually help you right now. There's a minor regression in MathJax 2.5 (see this discussion leading to the result you describe). This will be fixed in 2.5.1 and in the mean time you could set noReflows:false for the HTML-CSS output.

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.

How to fully justify texts programmatically (Delphi)?

How can I fully justify a block of text (like MS Word does, not only on the right and not only on the left but on both sides)?
I want to justify some texts (mainly arabic text) adjusted to certain screen size (some handheld device screen actually, and its text viewer doesn't have this function) and save this text as justified. So I can reload and reuse it again elsewhere.
(The problem with MS word is, that if you copy the justified text from MS Word and paste it to another editor it'll copy it un-justified).
Update : for now I'm thinking of doing it like this:
get-a-word
get-word-width
add-word-to-total-Word and add-Word-width-to-total-word-width
check if total-Word-width = myscreen-width then continue
else if total-Word-width is between myscree-wdith and (myscreen-width -3) then
add-spaces-To-total-word until it = myscreen-width
This is what I'm thinking now, but I put this question up and hope to see if there is a better solution, or somebody else already implemented it.
PS: I hope I have made my question clear and I'm sorry for bad expression if there is.
edit1 : changed the title to make it more clear.
If you want to justify plain text, you can only add extra spaces to the lines to get them align on the left and right. Unfortunately the character widths differ in fonts; so doing it this way will only work for a certain font, unless you limit yourself to monospaced fonts where all characters have the same size.
If you want a result like in Word, adding spaces won't cut it. Word will not add spaces, but stretch and shrink the existing spaces. This information is lost when you copy and paste it into another app.
Either way, justifying is an optimization problem. If you are interested in a good solution and its implementation: have a look a TeX. For an implementation that works on plain text with monospaced fonts have a look at par
There are some API calls that may help:
ExtTextOut and GetCharacterPlacement
Look at the GCP_JUSTIFY flag for GetCharacterPlacement
ExtTextOut is used by Canvas.TextRect
The problem you are going to face is always going to be differences in the rendering of the font. Word handles full justification by adjusting kerning as well as adjusting the number of pixels between words by a few (either way). The end result is lined up both margins. This pixel adjustment is done BOTH ways, and as evenly as possible.
To properly handle this in your portable device you will have to also perform the same algorithm for the display of the text there.
If this is not possible, then the ONLY way you can even get somewhat close would be to add whitespace between words.
As has been pointed out in other answers Word does full justification by stretching the existing spaces often by very small amounts. This is only possible if you have full control over how your text is drawn on the screen (which word - or any other windows program has).
You only real option in this regard would be to implement your own text viewer on the platform you are targeting. Eg you would need to draw the text on the screen yourself (any platform that allows games should allow you to draw on the screen). However this seems like an awful lot of trouble to get justified text.
Sorry couldn't be of more help.

Resources