Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using MathJax I need a solution for \ensuremath

Tags:

latex

mathjax

I'm using a MathJax in several projects and it generally works like a charm.

Today, however, I ran into a problem during the translation of a part of an existing LaTeX document with the following align-environment:

\begin{align}
  & (\lambda x.(\lambda y.(\lambda z.xyz)))abc \\
= & \text{\{ impliciete toepassing expliciet maken \}} \\
  & (((\lambda x.(\lambda y.(\lambda z.xyz)))a)b)c \\
= & \text{\{ \ensuremath{\beta}-reductie, substitutie van \ensuremath{x}door \ensuremath{a}\}} \\
  & ((\lambda y.(\lambda z.ayz))b)c \\
= & \{\text{\ensuremath{\beta}-reductie, \ensuremath{y\,:=b}}\} \\
  & (\lambda z.abz)c \\
= & \text{\{ \ensuremath{\beta}-reductie, \ensuremath{z\,:=c}} \\
 & abc \\ \boxed{} \end{align}

The result rendered with LaTeX is this (sorry for the Dutch text ;-):

enter image description here

The align-environment is essentially a math context, so if you want text, you need to enclose that text with \text{...}. But when you need again math symbols within that text, you escape the text context by enclosing the maths with \ensuremath{...}.

And MathJax renders it like:

enter image description here

That Mathjax centers everything doesn't matter, that is something I can handle with CSS. But the rendering of \ensuremath is a problem. Clearly MathJax doesn't support \ensuremath, but I can't think of a workable workaround where I can use math symbols in a text-context.

Ideally I'ld like to have a solution using an alternative LaTeX construction (hence the cross listing)

Any ideas?

like image 344
nanitous Avatar asked Apr 21 '26 21:04

nanitous


1 Answers

You should use $...$ or \(...\) in place of \ensuremath{...}. This seems more natural to me even in LaTeX itself (as \ensuremath is really designed for use within macros that might be used inside both text- and math-modes).

So you can do

\begin{align}
  & (\lambda x.(\lambda y.(\lambda z.xyz)))abc \\
= & \{\text{ impliciete toepassing expliciet maken }\} \\
  & (((\lambda x.(\lambda y.(\lambda z.xyz)))a)b)c \\
= & \{\text{ $\beta$-reductie, substitutie van $x$door $a$ }\} \\
  & ((\lambda y.(\lambda z.ayz))b)c \\
= & \{\text{ $\beta$-reductie, $y:=b$ }\} \\
  & (\lambda z.abz)c \\
= & \{\text{ $\beta$-reductie, $z:=c$ }\} \\
  & abc \\ \boxed{} \end{align}

I also put the \{ and \} outside the \text{}, though you can do them inside if you prefer.

The centering is probably due to CSS on your page, as MathJax left-justifies these by default.

like image 113
Davide Cervone Avatar answered Apr 26 '26 05:04

Davide Cervone