# hyperref error : ! Argument of \@providesfile has an extra }

Using a solution to adjust spacing in my document with LuaLaTeX, I run into this cryptic error, as soon as I use \label{} in a math environment:

(c:/texlive/2016/texmf-dist/tex/generic/oberdiek/se-pdfdoc.def
! Argument of \@providesfile has an extra }.
<inserted text>
\par
l.51 ...dblpnct{\hspace{0.08334em}}: PDFDocEncoding]

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?
{se-pdfdoc.def}{\@firstoftwo {\@hspacer }}\def \reserved@b {\@hspace \ETC.
! Paragraph ended before \@providesfile was complete.
\par
l.51 ...dblpnct{\hspace{0.08334em}}: PDFDocEncoding]

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.

File: se-pdfdoc.def 2016/05/16 v1.11 stringenc\dblpnct {\protect \let \reserved@
d =*\def \par }: PDFDocEncoding
! Argument of \@providesfile has an extra }.
<inserted text>
\par
l.51 ...dblpnct{\hspace{0.08334em}}: PDFDocEncoding]

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?
{se-pdfdoc.def}{\@firstoftwo {\@hspacer }}\def \reserved@b {\@hspace \ETC.
! Paragraph ended before \@providesfile was complete.
\par
l.51 ...dblpnct{\hspace{0.08334em}}: PDFDocEncoding]

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.

) [1
Non-PDF special ignored!


MWE:

\documentclass{scrbook}

\usepackage[pdfencoding=auto,pdfpagelabels=true,psdextra]{hyperref}   % PROBLEMATIC PACKAGE
\pdfstringdefDisableCommands{\def\dblpnct#1{}}   % TRIED TO FIX IT, BUT FAILED

\usepackage{luacode}
\usepackage{etoolbox}
\newrobustcmd\dblpnct[1]{%
\ifincsname\else
\ifmmode\else
\ifhmode
\unskip
\fi
\nolinebreak#1%
\fi
\fi
}
\makeatletter
% latex.ltx, line 4070:
\def\label#1{\@bsphack
\protected@write\@auxout{\let\dblpnct\@gobble}% <-- disable in \label
{\string\newlabel{#1}{{\@currentlabel}{\thepage}}}%
\@esphack}
\makeatother
\begin{luacode}
function dosub(s)
s = string.gsub(s, ':', '\\dblpnct{\\hspace{0.08334em}}:')
return(s)
end
\end{luacode}

\AtBeginDocument{%
}

\begin{document}

$$\label{eq:test}$$

\end{document}

• @cfr: doesn't work – Kyle_the_hacker Oct 11 '16 at 8:31
• Sorry about that. – cfr Oct 11 '16 at 15:30

You should move the \hspace from the gsub in the definition of \dblpnct so that you don't have to fight against the expansion of the \hspace too. Then you can use \NR@sanitize@labelname to sanitize the label name. I exagerated the inserted space to check if there are side effects.

\documentclass{scrbook}

\usepackage[pdfencoding=auto,pdfpagelabels=true,psdextra]{hyperref}   % PROBLEMATIC PACKAGE
\pdfstringdefDisableCommands{\def\dblpnct#1{}}   % TRIED TO FIX IT, BUT FAILED
%
\usepackage{luacode}
\usepackage{etoolbox}
\newrobustcmd\dblpnct[1]{%
\ifincsname\else
\ifmmode\else
\ifhmode
\unskip
\fi
\nolinebreak\hspace{#1}%
\fi
\fi
}

\begin{luacode}
function dosub(s)
s = string.gsub(s, ':', '\\dblpnct{1.08334em}:')
return(s)
end
\end{luacode}

\makeatletter
\AtBeginDocument{%
\ifpatchable*\NR@sanitize@labelname
{\pretocmd\NR@sanitize@labelname{\let\dblpnct\@gobble}{}{\failed}}
{}
}
\makeatother

\begin{document}

a:b

$$\label{eq:test}$$

a:b \label{ref:blub} a:b \ref{eq:test} a:b

\end{document}


• Using your solution, I get the name of the chapter inside labeled equations. MWE: \begin{document} \chapter{chap} $$\label{eq:test}$$ \end{document}  – Kyle_the_hacker Oct 11 '16 at 11:13
• Sorry I forgot to remove the \@onelevel@sanitize when changing from \patchcmd to \pretocmd. I edited the code, it should work now. – Ulrike Fischer Oct 11 '16 at 14:10
• Related issue – Kyle_the_hacker Oct 27 '16 at 21:23