1

I have some options to typeset a command line option with a comment inside

\verb|-interaction=nonstopmode -recorder -s prologues=2 -s outputtemplate="%j.mps"|

Because I need in many places (in fact there are other reasons), I use a command instead:

\newcommand{\metapostOptions}{\verb|-interaction=nonstopmode -recorder -s prologues=2-s outputtemplate="%j.mps"|}

There is a reason, complicated to explain, which prevents me from just escaping the percent like so: \%; in fact the text in the command is generated.

I can define the command only if i include this in change of catcode.

\catcode`\%=12
\newcommand{\metapostOptions}{\verb|-interaction=nonstopmode -recorder -s prologues=2-s outputtemplate="%j.mps"|}
\catcode`\%=14

Still I cannot use, because then

(./test.out) (./test-1.cpt

! LaTeX Error: \verb ended by end of line.

I really don't understand what happens and cannot help myself.

Help very much appreciated.

  • 4
    you used \verb with { which is wrong \verb{-i... but you can not use \verb in the argument of any command – David Carlisle May 20 '23 at 10:33
  • 3
    I can define the command only if i include this in change of catcode. no that avoids the errr but verb does not work in that context, just use \texttt – David Carlisle May 20 '23 at 10:35
  • I adapted my question. I have a reason that I cannot just escape the %.. I should have told before, sorry. I edited the question accordingly. – user2609605 May 20 '23 at 10:52
  • While you can use \verbdef in newverbs package, you may want to consider the alternative of modifying the "generator" to output \% instead of % in the first place. There are other alternatives such as https://tex.stackexchange.com/a/626166/250119 – user202729 May 20 '23 at 10:58
  • @user202729 I used the first suggestion. I have no access on the converter. – user2609605 May 21 '23 at 14:45
  • @David: also a solution. catcode inside newcommand. – user2609605 May 21 '23 at 14:45
  • I do not know what you mean by that, but most catcode changes in a new comnand will not do anything useful – David Carlisle May 21 '23 at 18:20

2 Answers2

3

You can define your own macro that reads in the replacement text in a verbatim way and store that in \metapostOptions:

\documentclass{article}

\NewDocumentCommand \newverbcontent { m v } {\newcommand#1{\texttt{#2}}}

\newverbcontent\metapostOptions |-interaction=nonstopmode -recorder -s prologues=2-s outputtemplate="%j.mps"|

\begin{document} Use the following command line options: \metapostOptions. \end{document}

enter image description here

Skillmon
  • 60,462
2

You can not use \verb in the argument of a command.

Use

\newcommand{\metapostOptions}{%
 \textt{-interaction=nonstopmode -recorder -s prologues=2-s outputtemplate="\%j.mps"}}
David Carlisle
  • 757,742