惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
N
Netflix TechBlog - Medium
P
Proofpoint News Feed
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
aimingoo的专栏
aimingoo的专栏
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
阮一峰的网络日志
阮一峰的网络日志
I
InfoQ
F
Fortinet All Blogs
J
Java Code Geeks
Last Week in AI
Last Week in AI
美团技术团队
大猫的无限游戏
大猫的无限游戏
有赞技术团队
有赞技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件

XeTeX and LaTeX

Author per chapter (a.k.a. Proceedings) Subscript and superscript in text mode Typesetting tilde or backslash Phantomas command First gloss line in italics (gb4e) Table lines starting with square bracket Filetype recognition in Vim Vim for XeTeX/LaTeX First word of a paragraph Tables Block comment Line spacing in tables Assign another catcode Newcommand with an optional argument LaTeX’s new era started: XeTeX
Verbatim text as command argument
noreply@blogger.com (Anonymous) · 2008-03-05 · via XeTeX and LaTeX

In my dissertation I will refer to the N|uu text corpus. The corpus has reference units which are called e.g. NA071112-01_E.008. I thought all the references to the text corpus are markup-worthy entities so I needed a command like \ru (short for reference unit) to markup those references with it like this: \ru{NA071112-01_E.008}.

As you know, the underscore “_” is a special character used in math mode for subscript. So it is not allowed to occur as a part of some string. I did not want to write \ru{NA071112-01\_E.008} instead. I looked for a way to feed commands verbatim text arguments.

I stumbled upon the fancyvrb package, which looks really promising for this, especially in the documentation on p. 17 where some magic aftersave is used. But the aftersave parameter is heavily underdocumented there. That’s just my luck. I could not find out what aftersave actually does and if it will enable me to write someting like \ru{NA071112-01_E.008}.

I then sought help at comp.text.tex (topic: fancyvrb problems) and Enrico Gregorio was so kind to write me this TeX code:


\def\ruspeciallist{\do\_} % add the special characters you need with "\do\X" (X is the characater)

\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{\box\rubox}

An extensively commented version is also there.

In the last line between “\dorufinish{” and “\box\rubox}” come all the commands you want to apply the the argument of \ru. BUT:

Enrico: “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.”

Ok, this certainly is a nice piece of code but it does not essentially allow verbatim text to be an argument of a command. It is just a work-around to get that verbatim text typeset somehow (and that's what I have originally asked for in the newsgroup). So, in that sense, verbatim text as argument still is an open issue.

Enrico — after I told him I actually may want to index that stuff — suggested a much simpler and elegant solution for my particular needs.

Anyway, if anybody of you readers finds out how to use the aftersave of fancyvrb package do inform me in the comments to this post. I’d really like to know. I think it has something to do with TeX’s \expandafter.