我过度使用了以下代码,
\makeatletter
\def\ifinstr#1#2{%
\def\@ifinstr##1#2##2\@nil{%
\ifstrempty{##2}{\@secondoftwo}{\@firstoftwo}}%
\@ifinstr#1\@@nil#2\@nil
}
\def\popleft#1#2{%
\edef\@tmpa{#1}%
\expandafter\@popleft\expandafter{\@tmpa}{#1}{#2}}
\def\@popleft#1#2#3{%
\ifinstr{#1}{|}
{\@@popleft{#2}{#3}\q@nil#1\q@stop}
{\@@popleft{#2}{#3}\q@nil#1|\q@stop}}
\def\@@popleft#1#2\q@nil#3|#4\q@stop{\edef#1{#4}\edef#2{#3}}
\DeclareRobustCommand*\assignvalues[2]{\@assignvalues{#1}{#2}}
\def\@assignvalues#1#2{%
\edef\@tmpb{#1}\edef\@tmpc{#2}%
\popleft\@tmpb\currentvalueA
\popleft\@tmpc\currentvalueB
\csedef{\currentvalueA}{\currentvalueB}%
\ifdefempty\@tmpb{}{\assignvalues\@tmpb\@tmpc}%
}
\makeatother
但是如果我以这种方式使用 caption 命令,这段代码就不起作用......
\assignvalues{bcaption}{Äußere Restfeuchte}
....
\end{pspicture}
\caption[Warscheinlichkeitsverteilung~\protect\bcaption]{\space~\protect\bcaption\space (AD)}
第一次编译成功,但第二次编译在 lof 文件中生成一个条目,以下条目将显示为
\contentsline {figure}{\numberline {1.12}{\ignorespaces Wahrscheinlichkeitsplot Äu\T 1\ss ere Restfeuchte Rohstoff C}}{11}{figure.caption.18}
有人知道问题可能出在哪里吗?肯定是上面的代码和标题参数的组合,这必须是可靠的。但我现在无法解决这个问题。
有任何想法吗?
更新 1:MWE(非工作超过一次)
\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern}
\usepackage{textcomp} % Euro-Zeichen etc...
\usepackage{etoolbox}
\usepackage{graphicx}
\usepackage{caption}[2008/08/24]
\usepackage{pstricks}
\usepackage{pst-all}
\usepackage{pstricks-add}
\makeatletter
\def\ifinstr#1#2{%
\def\@ifinstr##1#2##2\@nil{%
\ifstrempty{##2}{\@secondoftwo}{\@firstoftwo}}%
\@ifinstr#1\@@nil#2\@nil
}
\def\popleft#1#2{%
\edef\@tmpa{#1}%
\expandafter\@popleft\expandafter{\@tmpa}{#1}{#2}}
\def\@popleft#1#2#3{%
\ifinstr{#1}{|}
{\@@popleft{#2}{#3}\q@nil#1\q@stop}
{\@@popleft{#2}{#3}\q@nil#1|\q@stop}}
\def\@@popleft#1#2\q@nil#3|#4\q@stop{\edef#1{#4}\edef#2{#3}}
\DeclareRobustCommand*\assignvalues[2]{\@assignvalues{#1}{#2}}
\def\@assignvalues#1#2{%
\edef\@tmpb{#1}\edef\@tmpc{#2}%
\popleft\@tmpb\currentvalueA
\popleft\@tmpc\currentvalueB
\csedef{\currentvalueA}{\currentvalueB}%
\ifdefempty\@tmpb{}{\assignvalues\@tmpb\@tmpc}%
}
\makeatother
\newcommand{\blankimageX}{
\begin{figure}[!ht]
\begin{center}
\psset{xunit=\scalex cm,yunit=\scaley cm, runit=\scaler cm}
\psCancel{\begin{pspicture}(\xstart,\ystart)(\xend,\yend)
% Achsen
% X-Achse
\psline(\xstart,\yistart)(\xend,\yistart)
% Y-Achse
\psline(\xstart,\yistart)(\xstart,\yend)
\psline(\xend,\yistart)(\xend,\yend)
\psline(\xstart,\yend)(\xend,\yend)
\end{pspicture}}
\caption[Wahrscheinlichkeitsplot \bcaption]{Wahrscheinlichkeitsplot \bcaption nach Anderson-Darling}
\label{\lab}
\end{center}
\end{figure}
}
\begin{document}
\tableofcontents
\listoffigures
\chapter{Chapter A}
\assignvalues{scalex|scaley|scaler|xstart|xend|ystart|yend|yistart}{1|1|1|0|8|0|5|-1}
\assignvalues{bcaption|lab}{Äußere Restfeuchte|fig:picdesc}
\bcaption
\section{Section A}
\chapter{Chapter B}
\blankimageX
\section{Section B}
\end{document}
LG 金纳斯
答案1
代码很难理解;但问题在于你使用的\edef
输入Äußere
是非常很危险,因为它会产生打印字符的所有指令。
而是使用\protected@edef
可以包含这些“高位集”字符的标记列表;etoolbox
还提供\protected@csedef
。
以下是修改后的代码和一个最简单的示例:
\documentclass{scrreprt}
\usepackage[T1]{fontenc}
\usepackage[ansinew]{inputenc}
\usepackage{lmodern}
\usepackage{etoolbox}
\makeatletter
\def\ifinstr#1#2{%
\def\@ifinstr##1#2##2\@nil{%
\ifstrempty{##2}{\@secondoftwo}{\@firstoftwo}}%
\@ifinstr#1\@@nil#2\@nil
}
\def\popleft#1#2{%
\protected@edef\@tmpa{#1}%
\expandafter\@popleft\expandafter{\@tmpa}{#1}{#2}}
\def\@popleft#1#2#3{%
\ifinstr{#1}{|}
{\@@popleft{#2}{#3}\q@nil#1\q@stop}
{\@@popleft{#2}{#3}\q@nil#1|\q@stop}}
\def\@@popleft#1#2\q@nil#3|#4\q@stop{\protected@edef#1{#4}\protected@edef#2{#3}}
\DeclareRobustCommand*\assignvalues[2]{\@assignvalues{#1}{#2}}
\def\@assignvalues#1#2{%
\protected@edef\@tmpb{#1}\protected@edef\@tmpc{#2}%
\popleft\@tmpb\currentvalueA
\popleft\@tmpc\currentvalueB
\protected@csedef{\currentvalueA}{\currentvalueB}%
\ifdefempty\@tmpb{}{\assignvalues\@tmpb\@tmpc}%
}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\chapter{Chapter A}
%\assignvalues{scalex|scaley|scaler|xstart|xend|ystart|yend|yistart}{1|1|1|0|8|0|5|-1}
\assignvalues{bcaption|lab}{Äußere Restfeuchte|fig:picdesc}
\begin{figure}
\caption[Wahrscheinlichkeitsplot \bcaption]{Wahrscheinlichkeitsplot \bcaption{} nach Anderson-Darling}
\label{\lab}
\end{figure}
\end{document}