I would like to write a LaTeX document in which several Mathjax commands are shown as source code and compiled.
So I want to have a list of items and have them show up on, for example, the left side as source code for Mathjax e.g. a^2 and on the right side have it show what it will look like e.g. a², but I do not want to enter the code twice for maintenance reasons.
I tried to create a \newcommand for this myself, but failed with verbatim package and listings packages (mostly with improper alphabetic constant errors) and I have tried sverb package with demo environment and showexpl package wit LTXexample environment, but failed with both to have it display the code as it would have to be used with Mathjax (i.e. without math mode symbol $). The document will have to be used by very inexperienced Mathjax users so I do not want to confuse them with symbols they will not have to enter.
Any suggestions for me?
What I tried so far
defining a \newcommand
\usepackage{verbatim}
\newcommand{\cl}[1]{$#1$ & \lstinline{#1}} %use within a \tabular environment
In this case LaTeX tells me that I cannot use \verb in a new command.
\usepackage{listings}
\newcommand{\cl}[1]{$#1$ & \verb!#1!} %use within a \tabular environment
My ultimate goal is to list formulas and this works fine with certain things, but as soon as there is a command in there, e.g. \geq I receive a ! Improper alphabetic constant. error. I found out that I have to escape the \ in the listing with another \, such as \\geq, but of course that will not work for the first part of the command...
I used them like this:
\begin{document}
\begin{tabular}{c|c}
$F(x) \geq 0$ & \verb!F(x) \geq 0! \\
\hline
\cl{A(n+2)=A(n)+A(n+1)} \\
\hline
\cl{\geq} \\
\end{tabular}
\end{document}
imported environments
I found packages which aim to provide almost what I searched for:
\usepackage{sverb}
\begin{document}
\demo{}
$\geq$
\end{document}
This does perfectly what it intends to do, but in my particular case it is very unpractical, that it (of course) always displays the $ symbols. This is meant to be used by someone who does really not know about LaTeX/Mathjax at all and I did not succeed in explaining why these symbols are in the document, but do not need to be entered in Mathjax.
\usepackage{showexpl}
\begin{document}
\begin{LTXexample}
$\geq$
\end{LTXexample}
\end{document}
The result of this (for my document) was pretty much the same as in the above case.
I tried
filecontentspackage and use it via\lstinputlisting(fromlistingspackage) to show the code or via\inputto show the result. – Paul Gaborit Feb 11 '16 at 00:49