TransWikia.com

How to understand the "v-type" argument error described in xparse package documentation?

TeX - LaTeX Asked by David Hans on May 16, 2021

I’m getting myself familiar with the LaTeX3 new way of composing a customized command using the xparse package.

However, I don’t quite understand what does this line means from the documentation:

v Reads an argument “verbatim”, between the following character and its next occurrence,
in a way similar to the argument of the LATEX 2ε command verb. Thus
a v-type argument is read between two identical characters, which cannot be any
of %, , #, {, } or ␣. The verbatim argument can also be enclosed between braces,
{ and }. A command with a verbatim argument will produce an error when it
appears within an argument of another function.

I thought the "argument in another function" case looks like:

SomeCommand{CustomizedCommand+parameter+}

But when I try this example (MWE, using XeLaTeX):

documentclass{article}
usepackage{xparse}
NewDocumentCommand{Test}{mv}{
    (#1)(#2)
}
NewDocumentCommand{TestA}{v}{
    <#1>
}
begin{document}
TestA+Test{first}|second|+ par
TestA{Test{first}|second|}
end{document}

It output:

<Test{first}|second|>
<Test{first}|second|>

Looks like it just simply doesn’t execute the inner command. And there is no error thrown, which is as expected.

So I think there must be something wrong with my understanding, and I put it here just looking forward to a nice discussion with you. Thanks!


Besides, I tried to use pdfLaTeX compiler instead of XeLaTeX. But the output was (same source):

¡“Test–first ̋—second—¿
¡“Test–first ̋—second—¿

For this, I have no idea either.

One Answer

The v type reads the argument “verbatim”, which means roughly “everything is a normal character”, so TestA+Test{first}|second|+ reads everything between the two + as characters (a separates two tokens):

•T•e•s•t•{•f•i•r•s•t•}•|•s•e•c•o•n•d•|

rather than the usual:

Test•{•f•i•r•s•t•}•|•s•e•c•o•n•d•|

which means that in there Test is no longer a command, but just 5 characters.

As promised in the documentation, you get more or less the same with verb:

verb+Test{first}|second|+

Also note that the xparse documentation for the v argument warns you that:

A command with a verbatim argument will produce an error when it appears within an argument of another function.

so using a command with a v argument in the argument of any other command is not supported.


As for the output, pdfLaTeX uses by default the legacy OT1 encoding, which has a limited number of (128) characters, so the OT1 Computer Modern font doesn't have and a bunch of others. If you use the T1 encoding or a typewriter (ttfamily) font, it will show up correctly:

enter image description here

documentclass{article}
usepackage[T1]{fontenc}% for pdfTeX only
usepackage{xparse}
newcommandcmd[1]{#1}
NewDocumentCommand{TestA}{v}{
    <#1>
}
begin{document}
ttfamily
TestA+Test{first}|second|+ par
TestA{Test{first}|second|}
cmd{TestA{Test{first}|second|}} % ERROR: TestA inside cmd
end{document}

Correct answer by Phelype Oleinik on May 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP