我有小的MWE:
\batchmode
\documentclass[twoside]{book}
\usepackage[spanish]{babel}
\begin{document}
\chapter{Referencia \texorpdfstring{$<$}{<} }
\end{document}
这会导致(使用 pdflatex)出现错误:
! Argument of \language@active@arg> has an extra }.
<inserted text>
\par
l.5 \chapter{Referencia \texorpdfstring{$<$}{<} }
I've run across a `}' that doesn't seem to match anything.
For example, `\def\a#1{...}' and `\a}' would produce
this error. If you simply proceed now, the `\par' that
I've just inserted will cause me to report a runaway
argument that might be the root of the problem. But if
your `}' was spurious, just type `2' and it will go away.
Runaway argument?
! Paragraph ended before \language@active@arg> was complete.
<to be read again>
\par
l.5 \chapter{Referencia \texorpdfstring{$<$}{<} }
I suspect you've forgotten a `}', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.
...
关于如何以一般方式解决这个问题有什么建议吗?(问题也出现在其他字符上textorpdfstring
)
答案1
嗯...你把 MWE 降低太多了。你不应该hyperref
也加载吗?无论如何,<
在西班牙语 babel 中默认处于活动状态。我的解决方案(假设我无论如何都使用 unicode/utf8 编码)是始终使用:
\documentclass[twoside]{book}
\usepackage[T1]{fontenc}
\usepackage[spanish, es-noshorthands, shorthands=off]{babel}
\usepackage{hyperref}
\begin{document}
\chapter{Referencia \texorpdfstring{$<$}{<} }
\end{document}
这几乎在任何地方都有效。