0

Staying away from LaTeX for barely more than 2 years has devastating effects.

I think once I knew how to protect this stuff, but I have no idea now.

I defined the newcommand below to be faster in writing C++ code inline (and I have a similar macro for other languages). However, it looks like it doesn't really like the # of include statements:

\documentclass{article}

\usepackage{minted} \newcommand{\cpp}[1]{\mintinline{c++}{#1}}

\begin{document}

\noindent \mintinline{c++}{#include <iostream>} % ok \ \cpp{#include <iostream>} % renders as ##include &lt;iostream&gt;

\end{document}

Enlico
  • 2,592
  • mintinline like all verb commands can not be used in the argument or definition of another command. Here it makes # safe but that can not work as it has already been read by \cpp as a special character before minted sees it – David Carlisle Feb 28 '21 at 17:12
  • 1
    Can't test because I don't have a Python installation on my PC at the moment, but often with "verbatim" issues like this the "magic trick" is to avoid making the argument explicit in the \newcommand: \newcommand{\cpp}{\mintinline{c++}} might work. (Of course these kind of tricks making the "verbatim" argument explicit do not always work.) – moewe Feb 28 '21 at 17:13
  • @moewe yes that would work – David Carlisle Feb 28 '21 at 17:13
  • @moewe, it works, thanks. I think you can answer, or most probably mark this question as a duplicate of another one. – Enlico Feb 28 '21 at 17:15
  • 2
    You may also be interested in \newmintinline to define your own \mintinline-like command directly. – moewe Feb 28 '21 at 17:18
  • 1
    As far as duplicates are concerned I found https://tex.stackexchange.com/q/394072/35864 and https://tex.stackexchange.com/q/444122/35864. I think the first is a perfect match for your question. WDYT? – moewe Feb 28 '21 at 17:20
  • Yeah, I've marked the question as dup myself. – Enlico Feb 28 '21 at 17:52

0 Answers0