hyperref 错误:!\@providesfile 的参数有一个额外的 }

hyperref 错误:!\@providesfile 的参数有一个额外的 }

使用 LuaLaTeX 解决方案调整文档中的间距当我\label{}在数学环境中使用时,我遇到了这个神秘的错误:

(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.
<to be read again> 
\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.
<to be read again> 
\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!

梅威瑟:

\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{%
    \luaexec{luatexbase.add_to_callback("process_input_buffer", dosub, "dosub")}%
}

\begin{document}

\begin{equation}
\label{eq:test}
\end{equation}

\end{document}

答案1

您应该将 移出\hspace的定义中的 gsub,\dblpnct这样您就不必再与 的扩展作斗争了\hspace。然后您可以使用\NR@sanitize@labelname来清理标签名称。我夸大了插入的空间以检查是否有副作用。

\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{%
    \luaexec{luatexbase.add_to_callback("process_input_buffer", dosub, "dosub")}%
    \ifpatchable*\NR@sanitize@labelname
    {\pretocmd\NR@sanitize@labelname{\let\dblpnct\@gobble}{}{\failed}}
    {}
}
\makeatother

\begin{document}

a:b

\begin{equation}
\label{eq:test} 
\end{equation}

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

\end{document}

在此处输入图片描述

相关内容