I'm facing a weird problem when trying to compile a PDF that contains a quoted word that starts with "r" while using the babel package in Spanish and monospace fonts.
This minimal example
\documentclass[]{book}
\usepackage[spanish]{babel}
\begin{document}
\texttt{"rword"}
\end{document}
Fails with error
! Bad character code (-1).
\es@chf ->\char \hyphenchar \font
l.5 \texttt{"rword"}
A Unicode scalar value must be between 0 and "10FFFF.
I changed this one to zero.
The same document renders correctly if I either
- remove
\usepackage[spanish]{babel}
(need to render twice, though), - use
\usepackage[ensligh]{babel}
, - remove the monospace formatting (
"rword"
instead of\texttt{"rword"}
) - remove the quotes(
\texttt{rword}
instead of\texttt{"rword"}
) - remove the "r" (
\texttt{"word"}
instead of\texttt{"rword"}
) or change it to any other letter.
Adding any amount of spaces between the quote and the letter "r" still triggers the error.
And while other letters besides "r" do compile, some of them result in weird output. For example, this is the output from \texttt{"aword"}
I tried basically all LaTeX engines available on Texmaker (XeLaTeX, LuaLaTeX, PDFLaTeX and LatexMk) and they all fail with the same error. At this point I'm just baffled and confused by the specificity of this error.
"
for quotes in TeX."
a shorthand to access various accents and language features, you can disable that with\shorthandoff
\usepackage{fontspec}
on XeLaTeX or LuaLaTeX, or\usepackage[T1]{fontenc}
on PDFLaTeX. (But you probably left that out just to keep the MWE truly minimal.)"rword"
would display as ”rword”, inside two pairs of closing quotes. You almost certainly meant to write `` before r.