1

I would like to typeset an introduction to MathJAX/LaTeX formulae.

For that, I introduced a macro:

\newcommand{\showsource}[1]{$#1$ : \verb|#1|}

To typeset a math formula and then show its source.

But when I use it as

\showsource{\frac{1}{2}}

XeLaTeX complains about a missing $.

How can I write such a macro correctly?

Edit (MWE -- Manuel Kuehner)

\documentclass{article}

\newcommand{\showsourceA}[1]{$#1$}
\newcommand{\showsourceB}[1]{verb|#1|}

\begin{document}
\showsourceA{\frac{1}{2}}
\showsourceB{\frac{1}{2}}
\end{document}
4

1 Answer 1

1

Followin Steven B. Segletes' comment and his link:

Print small TeX code verbatim and render it

I created a new, working macro:

\newcommand{\showsource}[1]{$#1$ \quad {\ttfamily\detokenize{#1}} }

and it works on

\showsource{\frac{1}{2}}

enter image description here

(yes, the space after \frac is strange but I can live with it).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.