0

I'm writing a document (that uses the listings package) which aims to show the output of some LaTeX commands. I want to create a command that would allow me to typeset the command inline and its output in a single line. Writing

\noindent lorem
\\\LaTeXShow|{\Huge test text}|
\\ipsum

would display the following

enter image description here

The reason I want to do this is because I am writing a guide on LaTeX for my fellow ċlassmates and I want to show the output of having executed some LaTeX commands. The code snippet presented below is a minimum working example that represents some of the content I am currently writing

\documentclass{article}
\usepackage{listings}

\usepackage{xcolor}

\newcommand{\LaTeXShow}{\lstinline[language = {[latex]tex}, keywordstyle = {\color[HTML]{101094}}, basicstyle = {\ttfamily}]}

\begin{document}
    \noindent\LaTeXShow|{\Huge test text}| displays {\Huge test text}
    \\\LaTeXShow|{\Huge test text}| displays {\Huge test text}
    \\\LaTeXShow|{\Huge test text}| displays {\Huge test text}
    \\\LaTeXShow|{\huge test text}| displays {\huge test text}
    \\\LaTeXShow|{\LARGE test text}| displays {\LARGE test text}
\end{document}

As you can see, there is a pattern among the lines of the body of the document. If the desired command existed, then the document would look like this

\begin{document}
    \noindent\LaTeXShow|{\Huge test text}|
    \\\LaTeXShow|{\Huge test text}|
    \\\LaTeXShow|{\Huge test text}|
    \\\LaTeXShow|{\huge test text}|
    \\\LaTeXShow|{\LARGE test text}|
\end{document}

and the output would be

enter image description here

Note The command must use the lstinline command from the listings package. The reason behind this is because of the style options that package offers.

gfe
  • 415
  • This question answered my question thoroughly. In this scenario, the command would be \NewDocumentCommand\LaTeXShow{v}{\lstinline[language = {[latex]tex}, keywordstyle = {\color[HTML]{101094}}]{#1} displays \scantokens{#1\noexpand}} and I can call that macro by using vertical bar characters \LaTeXShow|{\Huge test text}|. – gfe Dec 08 '19 at 13:43
  • 1
    I've added a comment on the original answer there, you should really use \scantokens{#1\noexpand}\relax instead, or switch to the expl3 version in my answer. – Skillmon Dec 09 '19 at 20:17

0 Answers0