I am trying to define a function Lettrine from the lettrine one. I did it here successfully, but I need to add an optional argument to be able to use more lettrine features like ante:
\documentclass{article}
\usepackage{lettrine}
\def\eqifcase #1#2#3{\eqifcaseA #1#2#1{#3}\end }
\def\eqifcaseA #1#2#3{\ifx #1#2\eqifcaseDo{#3}\fi \eqifcaseA #1}
\def\eqifcaseDo #1\fi #2\end{\fi #1}
\def\LettrineX #1#2{\vspace{-4ex}\lettrine[lines=1,findent=-0.1em
\ifx\dummy#2\dummy\empty\else,#2\fi%
]{#1}{}}
\newcommand*{\Lettrine}[2][x]{\LettrineX{#2}{#1}}
\begin{document}\thispagestyle{empty}
\section{section 1}
\Lettrine[ante=«]{P}owerfull macro ! »
\section{section 2}
\Lettrine{P}owerfull macro !
\end{document}
It does not compile, with the error:
$ pdflatex MWE_lettrine_command7.tex
This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013)
restricted \write18 enabled.
entering extended mode
(./MWE_lettrine_command7.tex
LaTeX2e <2011/06/27>
Babel <3.9f> and hyphenation patterns for 15 languages loaded.
(/usr/share/texmf-dist/tex/latex/base/article.cls
Document Class: article 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texmf-dist/tex/latex/lettrine/lettrine.sty
(/usr/share/texmf-dist/tex/latex/graphics/keyval.sty)
Loading lettrine.cfg
(/etc/texmf/tex/latex/lettrine.d/lettrine.cfg)) (./MWE_lettrine_command7.aux))
! Incomplete \ifx; all text was ignored after line 17.
<inserted text>
\fi
<*> MWE_lettrine_command7.tex
If I add a \expandafter before lettrine, it changes nothing, but I am a newbbie for this kind of stuff. If I comment the \ifx line of code, it does compile and work.
The following \ifx MWE reproduces the same kind of architecture with the ifx expression inside an optional argument in a demonstration function. It compiles and works successfully:
\documentclass{article}
\usepackage{lettrine}
\newcommand*{\Test}[2][xxx]{option=#1; argument=#2}
\def\testX #1#2{%
\Test[\ifx\dummy#2\dummy\empty\else,#2\fi]{#1}%
}
\newcommand*{\test}[2][]{\testX{#2}{#1}}
\begin{document}\thispagestyle{empty}
With one argument: "\test{MAIN-ARG---ONLY-ONE}"\par
With two arguments: "\test[OPTION=2]{MAIN-ARG}"
\end{document}
Result:

I have quite no more hair at trying to figure out what I am doing wrong. Any idea please?



,in theifxwas not intended to separate list items, but to be a standard character in the output. The MWE shows it works I think. But I have to go deeper in your explanations. See you soon. – lalebarde May 21 '14 at 13:58\def\dropCap{#2}, and then use\dropCapinstead of#2inside\eqifcase {#2}{{P}{-0.8em}{T}{-0.6em}}{-0.1em}. Surprizingly, the default is trigged instead of the P case. If I add--\dropCap--somewhere, it is outputed in the pdf as--P--though ! Any idea please? – lalebarde May 21 '14 at 17:37\Lettrine{D'}- note the apostrophe added in the argument. It works with lettrine, but fails to compile here. It seems that\eqifcaserequires to eval arguments of the same length? – lalebarde May 21 '14 at 17:43\eqifcaseonly works with single token arguments. It could work with\dropCapif used both in the definition of the switch and its use, with for example\def\dropCap {D'}but\eqifcasecould not work withD'at either location. – May 21 '14 at 19:33\def\dropCap{\substring{#2}{1}{1}}%, then:\FPset\myindent\eqifcase {\dropCap}{{P}{-0.6em}{T}{-0.6em}}{-0.1em}, using the the fp (floating point) package to add a constant if an apostrophe follows. Then apply the result:findent=\myindent%. But the\eqifcasewith\dropCapas argument does not work:Argument of \eqifcase has an extra }. – lalebarde May 21 '14 at 22:18