3

I'm using the following command to create my own version of \mintinline:

\newcommand{\inline}[1]{{\mintinline[fontsize=\normalsize]{text}{#1}}}

This works except when I'm using the hash character. For instance:

\inline{Class#method()}

Which gets rendered with two hashes (i.e. Class##method()). When I replace my own command with \mintinline[fontsize=\normalsize]{text}{…}, everything is fine.

What am I doing wrong in my \newcommand definition?

  • 1
    as with most "verbatim" commands, you cannot include in another command using standard definition forms. – David Carlisle Oct 1 '17 at 11:17
5

Just avoid absorbing the text beforehand:

\documentclass{article}
\usepackage{minted}

\newcommand{\inline}{\mintinline[fontsize=\normalsize]{text}}

\begin{document}

Text \inline{Class#method()} text

\end{document}

enter image description here

However, the preferred method is with \newmintinline, so the defined command can take options in the standard way.

\documentclass{article}
\usepackage{minted}

\newmintinline[inline]{text}{fontsize=\normalsize}

\begin{document}

Text \inline{Class#method()} text

Text \inline[fontsize=\small]{Class#method()} text

\end{document}

enter image description here

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.