Text Formatting\hyperref get error with \verb

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
bio_amateur
Posts: 1
Joined: Sat Nov 21, 2009 10:45 pm

\hyperref get error with \verb

Post by bio_amateur »

It is okay to use

Code: Select all

\hyperref[sec:mysection]{region}
or

Code: Select all

\verb!region! 
separately. However, when I try to use

Code: Select all

\hyperref[sec:mysection]{\verb!region!}
and compile it, I get error

ERROR: Missing } inserted.
--- TeX said ---
<inserted text>
}
l.176 ...yperref[sec:define-region]{\verb!region!}
How do we resolve this?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

\hyperref get error with \verb

Post by gmedina »

Hi,

the standard verbatim command and environment cannot be used in the arguments of other commands.

In your particular example, you could use something like

Code: Select all

\documentclass{article}
\usepackage{hyperref}

\begin{document}

\hyperref[sec:mysection]{\texttt{region}}

\end{document}

If you really need to use some form of verbatim as argument, then you can use some of the features provided by the fancyvrb package to do something like the following:

Code: Select all

\documentclass{article}
\usepackage{fancyvrb}
\usepackage{hyperref}

\begin{document}

\SaveVerb{myverb}|region|

\hyperref[sec:mysection]{\UseVerb{myverb}}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply