1

I have a library of tikz pictures, eg.

\newcommand*{\mypic}[1]{
\begin{tikzpicture}
 %...
\end{tikzpicture}
 }

which I would like to print together with their names (including arguments). However,

\renewcommand{\show}[1]{\verb|#1|\quad #1}
\show{\mypic{a}}

produces

Package tikz Error: Sorry, some package has redefined the meaning of the math-mode dollar sign. This is incompatible with tikz and its calc library and might cause unrecoverable errors.

I guess \show is trying to expand its argument inside \verb. I experimented with \expandafter but it didn't help. When I replaced \verb| | with \texttt{}, \show didn't print the macro name at all.

3
  • \verb cannot appear inside another macro. Aug 18, 2020 at 5:03
  • 1
    Try instead \renewcommand{\show}[1]{\detokenize{#1}\quad #1} Aug 18, 2020 at 5:03
  • Also \show only takes a single token. If you want to print multiple, try \message{...} or \errmessage{...}. Aug 18, 2020 at 5:04

1 Answer 1

3

Firstly, it's better to not redefine primitive, for example \show. Just choose another command name. Then, \Verb from fvextra package is more robust than \verb, when used inside another macro.

\documentclass{article}
\usepackage{fvextra}
\usepackage{tikz}

\newcommand*{\mypic}[1]{
  \begin{tikzpicture}
    \node[draw, circle] {text}; 
  \end{tikzpicture}
}

\newcommand{\showTikzPic}[1]{\Verb|#1|\quad #1}

\begin{document}
\showTikzPic{\mypic{}}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .