Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fancyvrb problems

243 views
Skip to first unread message

Sven Siegmund

unread,
Mar 3, 2008, 12:19:08 PM3/3/08
to
Hello,

I am experimenting with the fancyvrb package. There is an example with
"aftersave" in the documentation on p. 16

I tried it, but I get an error when compiling it. My cource code is
this:

\documentclass{article}
\usepackage{fancyvrb}

\newcommand{\Vitem}[1]{%
\SaveVerb[aftersave={%
\item[\UseVerb{Vitem}]}]{Vitem}}

\begin{document}
\DefineShortVerb{\|}
\begin{description}
\Vitem|\MyCommand| mycommand
\end{description}
\end{document}

when I run latex testcmd, I get "! Improper alphabetic
constant." (Full log is below). I don't understand it. It is nothing
but the example from the documentation, but it does not work.

S.

---------full log-------
Z:\latex\diss>latex testcmd
This is pdfTeX, Version 3.141592-1.40.4 (MiKTeX 2.7)
Running pdftex...
This is pdfTeX, Version 3.141592-1.40.4 (MiKTeX 2.7) (INITEX)
entering extended mode
(C:\MiKTeX\tex\latex\config\latex.ini
("C:\Documents and Settings\All Users\Application Data\MiKTeX\2.7\tex
\generic\c
onfig\pdftexconfig.tex")
(C:\MiKTeX\tex\latex\base\latex.ltx (C:\MiKTeX\tex\latex\00miktex
\texsys.cfg)
./texsys.aux found


\@currdir set to: ./.


Assuming \openin and \input
have the same search path.


Defining UNIX/DOS style filename parser.

catcodes, registers, compatibility for TeX 2, parameters,
LaTeX2e <2005/12/01>
hacks, control, par, spacing, files, font encodings, lengths,
====================================

Local config file fonttext.cfg used

====================================
(C:\MiKTeX\tex\latex\00miktex\fonttext.cfg
(C:\MiKTeX\tex\latex\base\fonttext.ltx
=== Don't modify this file, use a .cfg file instead ===

(C:\MiKTeX\tex\latex\base\omlenc.def) (C:\MiKTeX\tex\latex\base
\t1enc.def)
(C:\MiKTeX\tex\latex\base\ot1enc.def) (C:\MiKTeX\tex\latex\base
\omsenc.def)
(C:\MiKTeX\tex\latex\base\t1cmr.fd) (C:\MiKTeX\tex\latex\base
\ot1cmr.fd)
(C:\MiKTeX\tex\latex\base\ot1cmss.fd) (C:\MiKTeX\tex\latex\base
\ot1cmtt.fd)))
====================================

Local config file fontmath.cfg used

====================================
(C:\MiKTeX\tex\latex\00miktex\fontmath.cfg
(C:\MiKTeX\tex\latex\base\fontmath.ltx
=== Don't modify this file, use a .cfg file instead ===

(C:\MiKTeX\tex\latex\base\omlcmm.fd) (C:\MiKTeX\tex\latex\base
\omscmsy.fd)
(C:\MiKTeX\tex\latex\base\omxcmex.fd) (C:\MiKTeX\tex\latex\base
\ucmr.fd)))
====================================

Local config file preload.cfg used

=====================================
(C:\MiKTeX\tex\latex\base\preload.cfg (C:\MiKTeX\tex\latex\base
\preload.ltx))
page nos., x-ref, environments, center, verbatim, math definitions,
boxes,
title, sectioning, contents, floats, footnotes, index, bibliography,
output,
===========================================
Local configuration file hyphen.cfg used
===========================================
(C:\MiKTeX\tex\generic\babel\hyphen.cfg
(C:\MiKTeX\tex\generic\hyphen\hyphen.tex)
(C:\MiKTeX\tex\generic\hyphen\dumyhyph.tex)
(C:\MiKTeX\tex\generic\hyphen\zerohyph.tex)
(C:\MiKTeX\tex\generic\xu-hyphen\xu-dehypht.tex
(C:\MiKTeX\tex\generic\hyphen\dehypht.tex
German Traditional Hyphenation Patterns `dehypht' Version 3.2a
<1999/03/03>
(Formerly known under the name `ghyph31' and `ghyphen'.)))
(C:\MiKTeX\tex\generic\xu-hyphen\xu-dehyphn.tex
(C:\MiKTeX\tex\generic\hyphen\dehyphn.tex
New German Hyphenation Patterns `dehyphn' Rev.31 <2001-05-07> (WaS)))
(C:\MiKTeX\tex\generic\xu-hyphen\xu-frhyph.tex
(C:\MiKTeX\tex\generic\hyphen\frhyph.tex
frhyph.tex - French hyphenation patterns (V2.12) <2002/12/11>)))
=================================
Applying patch file ltpatch.ltx
=================================
(C:\MiKTeX\tex\latex\base\ltpatch.ltx)
) )
Beginning to dump on file latex.fmt
(preloaded format=latex 2008.3.3)
4915 strings of total length 65241
44003 memory locations dumped; current usage is 144&42059
3290 multiletter control sequences
\font\nullfont=nullfont
\font\OMX/cmex/m/n/10=cmex10
\font\tenln=line10
\font\tenlnw=linew10
\font\tencirc=lcircle10
\font\tencircw=lcirclew10
\font\OT1/cmr/m/n/5=cmr5
\font\OT1/cmr/m/n/7=cmr7
\font\OT1/cmr/m/n/10=cmr10
\font\OML/cmm/m/it/5=cmmi5
\font\OML/cmm/m/it/7=cmmi7
\font\OML/cmm/m/it/10=cmmi10
\font\OMS/cmsy/m/n/5=cmsy5
\font\OMS/cmsy/m/n/7=cmsy7
\font\OMS/cmsy/m/n/10=cmsy10
3633 words of font info for 14 preloaded fonts
14 hyphenation exceptions
Hyphenation trie of length 23193 has 713 ops out of 35111
88 for language 5
235 for language 4
207 for language 3
2 for language 1
181 for language 0
0 words of pdfTeX memory
0 indirect objects
No pages of output.
Transcript written on latex.log.
entering extended mode
(testcmd.tex
LaTeX2e <2005/12/01>
Babel <v3.8h> and hyphenation patterns for english, dumylang,
nohyphenation, ge
rman, ngerman, french, loaded.
(C:\MiKTeX\tex\latex\base\article.cls
Document Class: article 2005/09/16 v1.4f Standard LaTeX document class
(C:\MiKTeX\tex\latex\base\size10.clo))
(C:\MiKTeX\tex\latex\fancyvrb\fancyvrb.sty
Style option: `fancyvrb' v2.6, with DG/SPQR fixes <1998/07/17> (tvz)
(C:\MiKTeX\tex\latex\graphics\keyval.sty)
No file fancyvrb.cfg.
)
No file testcmd.aux.
! Improper alphabetic constant.
<to be read again>
\MyCommand
l.11 \Vitem|\MyCommand
| mycommand
?

Joseph Wright

unread,
Mar 3, 2008, 12:46:45 PM3/3/08
to
On Mar 3, 5:19 pm, Sven Siegmund <sven.siegm...@gmail.com> wrote:
> Hello,
>
> I am experimenting with the fancyvrb package. There is an example with
> "aftersave" in the documentation on p. 16
>
> I tried it, but I get an error when compiling it. My cource code is
> this:
>
> \documentclass{article}
> \usepackage{fancyvrb}
>
> \newcommand{\Vitem}[1]{%
> \SaveVerb[aftersave={%
> \item[\UseVerb{Vitem}]}]{Vitem}}
>
> \begin{document}
> \DefineShortVerb{\|}
> \begin{description}
> \Vitem|\MyCommand| mycommand
> \end{description}
> \end{document}
>
> when I run latex testcmd, I get "! Improper alphabetic
> constant." (Full log is below). I don't understand it. It is nothing
> but the example from the documentation, but it does not work.
>
> S.
>

It's not quite the example given, though. You have added [1] to the
\newcommand, which is where the trouble stems from. Try:

\documentclass{article}
\usepackage{fancyvrb}

\newcommand{\Vitem}{%


\SaveVerb[aftersave={%
\item[\UseVerb{Vitem}]}]{Vitem}}

\begin{document}
\DefineShortVerb{\|}
\begin{description}
\Vitem|\MyCommand| mycommand
\end{description}
\end{document}

instead.

Joseph Wright

Enrico Gregorio

unread,
Mar 3, 2008, 12:50:43 PM3/3/08
to
Sven Siegmund <sven.s...@gmail.com> wrote:

> Hello,
>
> I am experimenting with the fancyvrb package. There is an example with
> "aftersave" in the documentation on p. 16
>
> I tried it, but I get an error when compiling it. My cource code is
> this:
>
> \documentclass{article}
> \usepackage{fancyvrb}
>
> \newcommand{\Vitem}[1]{%
> \SaveVerb[aftersave={%
> \item[\UseVerb{Vitem}]}]{Vitem}}
>
> \begin{document}
> \DefineShortVerb{\|}
> \begin{description}
> \Vitem|\MyCommand| mycommand
> \end{description}
> \end{document}
>
> when I run latex testcmd, I get "! Improper alphabetic
> constant." (Full log is below). I don't understand it. It is nothing
> but the example from the documentation, but it does not work.

Your \Vitem is looking for an argument, which is incorrect.

\newcommand{\Vitem}{%


\SaveVerb[aftersave={%
\item[\UseVerb{Vitem}]}]{Vitem}}

Ciao
Enrico

Sven Siegmund

unread,
Mar 3, 2008, 2:24:19 PM3/3/08
to
Ok, I see the error. Your corrected examples work. But I still don't
get the meaning and usage of the aftersave parameter.

I was looking for it because I need to write me a command which could
take verbatim text as an argument. Practically I want to have a
command \ru which takes a string as argument. The purpose of the
command \ru is not important, but let's say I want that string written
in red proportional serif font and underline it. I want to use it like
\ru{1a2b3c} and the serult shall be the string 1a2b3c written in red
and underlined.

The problem is, that the arguments I have to write into \ru do contain
the underscore character. They look like NA175622-01_A. I know I can
write NA175622-01\_A instead, but this is not acceptable for certain
automatization and scripting reasons. There have to be
\ru{NA175622-01_A} in the tex source code. No I am desperately looking
for a way to define the \ru command similar to:

\providecommand{\ru}[1]{some stuff around #1 but #1 contains forbidden
characters}

How to do this?

Enrico Gregorio

unread,
Mar 3, 2008, 4:37:33 PM3/3/08
to
Sven Siegmund <sven.s...@gmail.com> wrote:

If the only problematic character is the underscore, the problem is
"easily" solved:

===== in the preamble =====
\newbox\rubox
\def\ru{\afterassignment\dorusetup\let\next= }
\def\dorusetup{\setbox\rubox=\hbox\bgroup
\catcode`\_=12 \aftergroup\dorufinish}
\def\dorufinish{\underline{\color{red}\box\rubox}}
===== in the document =====
Some black text \ru{NA175622-01_A} and other black text after it
=====

The macro \ru simply swallows the open brace (so the string to process
/must/ go between braces) and expands the \dorusetup macro which
starts building a box but considering the underscore a normal character;
when the box is finished by the matching closing brace, the macro
\dorufinish comes into action: it underlines the contents of the
box typesetting it in red.

You need to use a T1-encoded font which has an underscore in the
underscore position (\usepackage[T1]{fontenc}). Otherwise some more
work is needed.

Ciao
Enrico

Sven Siegmund

unread,
Mar 4, 2008, 3:27:36 AM3/4/08
to

> If the only problematic character is the underscore, the problem is
> "easily" solved:

Well, yes, the only problematic character is the underscore, but why
not learn the universally correct solution right away? What if some
other time in a similar task more special characters will intervene?
...

> You need to use a T1-encoded font which has an underscore in the
> underscore position (\usepackage[T1]{fontenc}). Otherwise some more
> work is needed.

Sorry, but I cannot work with T1 fonts. I actually must use XeTeX and
TTF/OTF fonts and have my source Unicode-encoded.

The thing is, that I do not want the command \ru to put the things red
and underline them, but some other things with them, i.e. set a serif
font and maybe later a counter in there or some indexing features. I
thought besindes some TeX code or some messy fancyvrb command I will
eventually end up with a clearly written command as I stated above
where I come only with #1:

\providecommand{\ru}[1]{some stuff around #1 but #1 contains
forbidden
characters}

S.

Enrico Gregorio

unread,
Mar 4, 2008, 4:30:34 AM3/4/08
to
Sven Siegmund <sven.s...@gmail.com> wrote:

> > If the only problematic character is the underscore, the problem is
> > "easily" solved:
>
> Well, yes, the only problematic character is the underscore, but why
> not learn the universally correct solution right away? What if some
> other time in a similar task more special characters will intervene?
> ...

Simply define a list of the special characters:

\def\ruspeciallist{\do\_\do\#} % add the characters you need

\def\rucatcodes{\def\do##1{\catcode`##1=12 }\ruspeciallist}

\newbox\rubox
\def\ru{\afterassignment\dorusetup\let\next= }
\def\dorusetup{\setbox\rubox=\hbox\bgroup

\rucatcodes \aftergroup\dorufinish}


\def\dorufinish{\underline{\color{red}\box\rubox}}

In this way every special character receives the correct treatment. Of
course, not the braces, at least with this code. But without precise
specifications, it's difficult to say more.

> > You need to use a T1-encoded font which has an underscore in the
> > underscore position (\usepackage[T1]{fontenc}). Otherwise some more
> > work is needed.
>
> Sorry, but I cannot work with T1 fonts. I actually must use XeTeX and
> TTF/OTF fonts and have my source Unicode-encoded.

Not a problem: TTF/OTF fonts do have an underscore in the correct
position.

> The thing is, that I do not want the command \ru to put the things red
> and underline them, but some other things with them, i.e. set a serif
> font and maybe later a counter in there or some indexing features. I
> thought besindes some TeX code or some messy fancyvrb command I will
> eventually end up with a clearly written command as I stated above
> where I come only with #1:
>
> \providecommand{\ru}[1]{some stuff around #1 but #1 contains
> forbidden
> characters}

The mechanism is there. After "\aftergroup\rufinish" you can say
whatever you need to set the fonts and \rufinish can do some other
postprocessing, as seen in the sample macro. For the indexing thing
it's more difficult, but there is \scantokens from e-TeX which can help.

You're not helping us, though: why don't you say precisely what you
plan to do?

Ciao
Enrico

Sven Siegmund

unread,
Mar 4, 2008, 4:59:43 AM3/4/08
to
Hi Enrico, yes, this works wonderfully. Thanks a lot.

Would you mind explaining the code to me? Just write some comments to
what it does. What I figured out is this:

\def\ruspeciallist{\do\_} % add the special characters you need with
"\do\X" (X is the characater), but actually this define a command
\ruspeciallist where ... ? what does the "\do" mean?

\def\rucatcodes{\def\do##1{\catcode`##1=12 }\ruspeciallist} %define
another command \rucatcodes which assigns catcode 12 (Other Character)
to any character in the \ruspeciallist. But what is the argument #1
and why it is written as ##1 and what means the ` after \catcode? is
there another command \do defined somewhere in there?

\newbox\rubox % make a box called \rubox

\def\ru{\afterassignment\dorusetup\let\next= } % define a command \ru
which does what ??? what is the \let\next=?

\def\dorusetup{\setbox\rubox=\hbox\bgroup % ??

\rucatcodes \aftergroup\dorufinish} % ??

\def\dorufinish{\box\rubox} % output the text which is in the \rubox,
output it as a box

If you could extensively comment those commands It would help me a lot
to understand this low level TeX stuff.

S.

Sven Siegmund

unread,
Mar 4, 2008, 5:24:04 AM3/4/08
to

> You're not helping us, though: why don't you say precisely what you
> plan to do?

I am sorry. I did not know that it will need all these TeX commands. I
did expect some easy command understandable for a LaTeX (actually
XeTeX) beginner like me, which I could later modify and expand.

At the moment I do not want anything but to type the arguments of \ru
in the main font like the other surrounding text. \ru Stands actually
for reference units of some other text corpus, and there is some
automatization around which is why it is not acceptable in the TeX
document to break the names of the reference units with the escape
sequence for the underscore character. Later I want the \ru command be
expanded in a way that a list of all referenced units (all the
arguments of \ru ever written in the tex document) will get
automatically generated the same way as e.g. index gets generated
where it will show on which page of the document which reference unit
gets mentioned.

S.

Enrico Gregorio

unread,
Mar 4, 2008, 5:39:02 AM3/4/08
to
Sven Siegmund <sven.s...@gmail.com> wrote:

> Hi Enrico, yes, this works wonderfully. Thanks a lot.
>
> Would you mind explaining the code to me? Just write some comments to
> what it does. What I figured out is this:
>
> \def\ruspeciallist{\do\_} % add the special characters you need with
> "\do\X" (X is the characater), but actually this define a command
> \ruspeciallist where ... ? what does the "\do" mean?
>
> \def\rucatcodes{\def\do##1{\catcode`##1=12 }\ruspeciallist} %define
> another command \rucatcodes which assigns catcode 12 (Other Character)
> to any character in the \ruspeciallist. But what is the argument #1
> and why it is written as ##1 and what means the ` after \catcode? is
> there another command \do defined somewhere in there?

=== commented code ===
%% Define a list macro to contain the characters that need special
%% treatment, just following the example: \do\<char>


\def\ruspeciallist{\do\_\do\#} % add the characters you need

%% Now define the \do macro (which has no fixed meaning) to
%% process the list


\def\rucatcodes{\def\do##1{\catcode`##1=12 }\ruspeciallist}

%% The macro \rucatcodes first of all redefines \do; since \do must
%% have a parameter, # characters must be duplicated, because
%% we are inside a definition (see TeX by Topic, a free book on CTAN
%% for details.
%% After redefining \do, we put \ruspeciallist, so that \do does
%% its thing: at the end \rucatcodes is equivalent to say
%%
%% \catcode`\_=12 \catcode`\#=12
%%
%% The advantage is that all special characters are collected in
%% one place and it is easy to extend the list without obscuring
%% the main macro definition.

\newbox\rubox

\def\ru{\afterassignment\dorusetup\let\next= }

%% \let is an assignment; a call like \ru{abc} expands to
%%
%% \afterassignment\dorusetup\let\next= {
%%
%% \next is a scratch macro, we don't need it for this application;
%% but it removes the open brace from the input. After this the
%% \dorusetup macro is expanded

\def\dorusetup{\setbox\rubox=\hbox\bgroup

\rucatcodes \aftergroup\dorufinish}
%% We store a box in the box register \rubox; it's an \hbox
%% and we use the feature that boxes can start with \bgroup, i.e.,
%% an implicit open brace; the closing brace will be the one after
%% the string (abc in my example). Inside the box we execute
%% \rucatcodes, so the special characters will be read in as printable
%% ones. Next we set aside a token, \dorufinish, which will be
%% expanded when the box will be finished (a box is a group).

\def\dorufinish{\underline{\color{red}\box\rubox}}

%% Now we have the box in the box register \rubox and we can do
%% what we want with it.
=== end of commented code ===

A limit of this approach is that the string is never read as an
argument, so that it is not available for, say, writing an index
entry: we have it only in typeset form, inside the box.

For this a slightly different approach must be followed.

Ciao
Enrico

Enrico Gregorio

unread,
Mar 4, 2008, 6:24:57 AM3/4/08
to
Sven Siegmund <sven.s...@gmail.com> wrote:

Now I see better the problem. There is a much simpler solution if you
don't need to write math formulas (which is likely, isn't it?). Just
say

\catcode`\_=12

in the preamble of your document and define \ru as you like. In the
event that a formula needs a subscript use \sb instead of the
underscore. Of course this won't work for other special characters.

For the list of references, look at the glossaries package, recently
updated.

Ciao
Enrico

Sven Siegmund

unread,
Mar 4, 2008, 9:25:38 AM3/4/08
to
Wonderful (-: This TeX command I can well understand by now.

S.

0 new messages