4

I use the following code excessivle,

\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

But this piece of code doesn't work if i use the caption command in this way...

\assignvalues{bcaption}{Äußere Restfeuchte}

....

\end{pspicture}
\caption[Warscheinlichkeitsverteilung~\protect\bcaption]{\space~\protect\bcaption\space (AD)} 

The first compile works, but the second one generates an entry in the lof file the following entry will be shwon as

\contentsline {figure}{\numberline {1.12}{\ignorespaces Wahrscheinlichkeitsplot Äu\T 1\ss ere Restfeuchte Rohstoff C}}{11}{figure.caption.18}

Has anybody an idea what the problem could be, for sure its a combination of the code above and the caption argument, which has to be robust. But I cannot solve the problem at the moment.

Any ideas?

Update 1: MWE (non Working more than one times)

\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 Goldnas

3
  • It's rather hard to tell by eye what that code is doing, pleas always post code in the form of a complete small document that shows the problem. Sep 5 '12 at 12:58
  • Welcome to TeX.SX! Please, transform the code snippet into a minimal document we can play with.
    – egreg
    Sep 5 '12 at 13:05
  • I will do the MWE, hint, I have asked at one more place in the net, see the same question @ mrunix.de/forums/showthread.php?t=73700&page=2
    – Goldnas
    Sep 5 '12 at 13:16
3

It's quite hard to follow the code; but the problem is in the fact that you're using \edef on input such as Äußere which is very dangerous as it produces all the instructions to print the characters.

Use \protected@edef instead for the token lists that can contain these "high bit set" characters; etoolbox provides also \protected@csedef.

Here's the amended code with a minimal example:

\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}
1
  • @Goldnas if this solution has solved the problem, don't forget to accept it using the green check mark :)
    – cmhughes
    Sep 5 '12 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.