Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

For a specific biblatex style, I have declared a bibliography option which takes a name, as in

\DeclareBibliographyOption{myname}{\edef\somename{#1}}

Now LaTeX yields an error if the value of this option consists of braces, such as myname=M{\"u}ller:

! You can't use `macro parameter character #' in horizontal mode.
\@removeelement #1#2#3->\def \reserved@a ##1,#1,##
                                                  2\reserved@a {##1,##2\rese...

l.59 \ProcessOptions\relax

Is there a way to work around this? If not, is there a way to expand a macro in such a way that braces disappear? My aim is to test for string equivalence via \ifdefstring, and the test returns false if M{\"u}ller is compared to M\"uller, as in

\edef\x{M{\"u}ller}
\edef\y{M\"uller}
\ifdefstrequal{\x}{\y}{TRUE}{FALSE}

which will return FALSE.

share|improve this question
    
Passing M{\"u}ller through \edef is impossible and it wouldn't solve the problem anyway, because \edef doesn't touch braces that don't delimit arguments to commands. –  egreg Oct 29 '12 at 15:08
    
I'm not sure I understand. If I pass M{\"u}ller to \edef, it expands to M{ü}ller, which is one step closer to what I want. Why is it "impossible"? –  JSpitzm Oct 29 '12 at 15:13
    
No, \"u expands to the set of instructions for printing "ü", which is very different from a simple token ü. And \edef\x{\"u} will always raise errors: the command \" cannot go inside \edef. –  egreg Oct 29 '12 at 15:28
    
Hm, seemed to work good enough for my purpose (I compare two \edefed macros via etoolbox's \ifdefstrequal). Now the question is: is there a way to fully expand a string for testing, including macros and nested braces? –  JSpitzm Oct 29 '12 at 15:32
    
Are the braces you need to strip off just like in M{\"u}ller or is there something more complicated? –  egreg Oct 29 '12 at 15:36
show 4 more comments

1 Answer 1

up vote 4 down vote accepted

You can't use \edef in this context: \edef\x{...\"u...} will always fail.

If you are using UTF-8 for your files and your author can appear in the three forms

M{\"u}ller
M\"uller
Müller

then these macros can be what you want:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}

\makeatletter
\def\stripbraces#1#2{%
  \begingroup
  \def\IeC##1{##1}%
  \protected@edef\@tempa{#1}%
  \gdef\@gtempa{}%
  \expandafter\@stripbraces\@tempa\@nil
  \endgroup
  \let#2\@gtempa
}
\def\@stripbraces#1{%
  \ifx#1\@nil\else
    \expandafter\gdef\expandafter\@gtempa\expandafter{\@gtempa#1}%
    \expandafter\@stripbraces
  \fi
}

\makeatother

\begin{document}

\stripbraces{M\"uller}{\x}
\stripbraces{M{\"u}ller}{\y}
\stripbraces{Müller}{\z}

\ifdefstrequal{\x}{\y}{TRUE}{FALSE}

\ifdefstrequal{\x}{\z}{TRUE}{FALSE}

\ifdefstrequal{\y}{\z}{TRUE}{FALSE}

\stripbraces{Øre}{\x}
\stripbraces{{\O}re}{\y}
\stripbraces{\O re}{\z}

\ifdefstrequal{\x}{\y}{TRUE}{FALSE}

\ifdefstrequal{\x}{\z}{TRUE}{FALSE}

\ifdefstrequal{\y}{\z}{TRUE}{FALSE}

\stripbraces{Gauß}{\x}
\stripbraces{Gau{\ss}}{\y}
\stripbraces{Gau\ss}{\z}

\ifdefstrequal{\x}{\y}{TRUE}{FALSE}

\ifdefstrequal{\x}{\z}{TRUE}{FALSE}

\ifdefstrequal{\y}{\z}{TRUE}{FALSE}

\end{document}

All the tests yield "TRUE".

However this would fail for Fran{\c{c}}ais and Fran{\c c}ais. So the final answer depends on your needs.

share|improve this answer
    
Thanks, @egreg, this seems to work for my cases. For some reason, however, it does not work for values passed through \DeclareBibliographyOption, which seems to do some expansion. I.e. with \DeclareBibliographyOption{myname}{\def\myname{#1}} and myname=M\"uller the \"u is expanded. –  JSpitzm Oct 29 '12 at 16:54
    
@JSpitzm Try \stripbraces{#1}{\myname} instead of \def\myname{#1} –  egreg Oct 29 '12 at 17:25
    
this fails as well. It seems the \"u is already expanded when passed as #1 within \DeclareBibliographyOption. –  JSpitzm Oct 29 '12 at 17:33
    
@JSpitzm Sorry, but without a real example it's impossible to say more. –  egreg Oct 29 '12 at 17:37
    
Nevermind, it'll do for now without the bibliography option approach (I'll provide an alternative way to set the respective name). The real example is my biblatex-publist package on CTAN. –  JSpitzm Oct 29 '12 at 17:46
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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