1

I have following snippet of code:

\documentclass[11pt, a4paper]{article}
\begin{document}
\newcommand{\test}[0]{`\verb£Test£'}
\test

`\verb£Test£'
\end{document}

The second scenario works as I want: the accents around test are in the same font. However, when I nest it in the test command, the closing accent is in the same font as verbatim. Why is that? And how can I fix this?

It looks like this:

enter image description here

This is of course a trivial example, but I want to use accents around verbatim inside more complex commands.

Thanks, Yves

2
  • 2
    \newcommand{\test}[0]{`\verb£Test£'} is a syntax error, you can not use \verb in the argument of another command. Commented Jul 8, 2016 at 9:39
  • 1
    Also note that £ is only safe to use as a \verb delimiter if you are using a legacy 8bit encoding such as latin1, if you use UTF-8 then it will not work. Commented Jul 8, 2016 at 9:42

1 Answer 1

3

You can't have \verb inside the argument to another command (including \newcommand).

The newverbs package provides “quoted verbatim” out of the box and also features \newverbcommand to do many more things.

\documentclass{article}

\usepackage{newverbs}

\begin{document}

\qverb|test\*&}|

\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 .