Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to create an inline verbatim text for a regular expression. The verbdef package does not like when I put curly braces into its second argument. I tried with escaping backslashes but that did not work.

\documentclass{article}

\usepackage{verbdef}
\verbdef{\re2}{([^/]*/){3}}

\begin{document}

What is the meaning of the \re2 regular expression?

\end{document}

I got the following error message:

(/usr/share/texmf/tex/latex/ltxmisc/verbdef.sty)

! Too many }'s.

l.4 \verbdef{\re2}{([^/]*/){3}}

I looked for a long name of curly brace like \curlybraceleft but did not find one.

How can I solve this typesetting problem?

share|improve this question
    
Welcome to TeX.sx! A tip: If you indent lines by 4 spaces or enclose words in backticks `, they'll be marked as code, as can be seen in my edit. You can also highlight the code and click the "code" button (with "{}" on it). –  zeroth Mar 17 '13 at 18:55
    
Thanks, both the welcoming and the typesetting tip. And the edit. –  Gergely Mar 17 '13 at 18:59
    
You are welcome, please edit the question adding where the \begin{document} should be placed, I am not familiar with the verbdef package and whether \verbdef must only be called in the preamble? :) –  zeroth Mar 17 '13 at 19:06
    
Thanks, egreg, it made it work. –  Gergely Mar 17 '13 at 19:15
    
zeroth, I made a minimal example that showed the error message and the problem. When you want to use that inline verbatim text, you simply use the \re macro that was being defined in the preamble. –  Gergely Mar 17 '13 at 19:18
show 2 more comments

1 Answer 1

up vote 3 down vote accepted

The documentation of verbdef is indeed rather scanty. Your attempt has two issues.

First of all you can't define a command that has digit and letters in its name: either the name is a single digit or letters only.

Second issue: if the text to be stored verbatim has braces in it, you have to use a syntax like the ordinary \verb command, so for instance

\verbdef{\re}|([^/]*/){3}|

where the delimiter character (here |) does not appear in the verbatim text.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.