1

Whenever I want to write an inline piece of code of LaTeX by using the listings package, I have to use the following command:

\lstinline[language={[latex]tex}, keywordstyle={\color[HTML]{101094}}]|\begin{document}|
\lstinline[language={[latex]tex}, keywordstyle={\color[HTML]{101094}}]|\end{document}|
\lstinline[language={[latex]tex}, keywordstyle={\color[HTML]{101094}}]|{\Huge test text}|

Note that the text to be typeset is \begin{document} and is enclosed within two vertical bar characters (i.e. |) in order to accept underscores and braces within the command argument. What I want to do is to create a command that would make me not to type all the options from the \lstinline command

\LaTeXLST|\begin{document}|
\LaTeXLST|\end{document}|
\LaTeXLST|{\Huge test text}|

Note 1 I tried to do the following with no avail.

\newcommand\LaTeXLST[1]{\lstinline[language={[latex]tex}, keywordstyle={\color[HTML]{101094}}]|#1|}

Note 2 I thought in creating an lst style that would define the language and the keywordstyle, but the idea of creating a command is more appealing since it requires less keypressings.

\lstinline[style=mylatex]|\begin{document}|

Note 3 I know LateX only accepts braces as argument delimiters but I want to mimick the behavior of the \lstinline package in order to accept vertical bars as command arguments delimiters. I've been reading the documentation on the listings package and you can use "any character not in the code" (p. 4) to delimit the code.

The reason I want to do this is because I'm working on a guide on LaTeX for my fellow classmates. For this reason, I need to constantly typeset code listings and inline LaTeX code within the document. I am using the listings because I can define an style and share that style among all the pieces of code that were typeset through the listings commands (i.e. \lstinline, \lstinputlisting, the lstlisting environment).

gfe
  • 415
  • 3
    Scanning the argument breaks verbatim. Just don't scan it: \newcommand\LaTeXLST{\lstinline[language={[latex]tex}, keywordstyle={\color[HTML]{101094}}]} – Henri Menke Dec 08 '19 at 04:17
  • You are right. That work as intended, therefore you have answered the question throughly. However, a new question arises. I've posted it here. – gfe Dec 08 '19 at 07:13

0 Answers0