TransWikia.com

Environment or command to handle multiple situations with the lettrine package

TeX - LaTeX Asked on March 16, 2021

I wrote my own command to put the first letter bigger.

But then I discovered the lettrine package which does more interesting things. Now I would like to have an environment or a command from which to handle various situations:

  1. Normal cases

  2. Cases with only one letter (disastrous exit)

  3. Cases with previous content (for example a number)

  4. Cases with quotes, and if possible combining the content with textquote from the csquotes package

This is my EMV:

documentclass[ebook,10pt,twoside,openright,showtrims]{memoir}
usepackage{lipsum}
usepackage{xcolor}  
usepackage{lettrine}  
newcommand*ruleline[1]{parnoindentraisebox{.8ex}{makebox[linewidth]{{color{red}hrulefill}hspace{1ex}raisebox{-.8ex}{#1}hspace{1ex}{color{red}hrulefill}}}}
renewcommandsubsubsecheadstyle{Largenoindentruleline}
renewcommand{LettrineFontHook}{color{red}}

newenvironment{body}{%
    addvspace{topsep}% Space above
}{%
    unskippar
    addvspace{topsep}% Space below
    %needspace{15baselineskip}
}


begin{document}

    begin{body}    
    lettrine[findent=.3em]{A}{l} lipsum[1] %1. normal case
    end{body}  

    begin{body}
    lettrine[findent=.3em]{Y} lipsum[2]] %2. case unique character (disaster)
    end{body}  

    begin{body}
    lettrine[findent=.3em, ante={1. }]{C}{on} lipsum[3] %3. case  with "ante" content (number)
                                                            
    end{body}  
        
    begin{body}
    lettrine[findent=.3em, ante={"}]{Q}{uoted"} lipsum[4] %4. case    with "ante" (quote)
                                                            %   who to combine with txtquote{} of csquotes package
    
end{body}
            
end{document}

This is the ouput:

enter image description here

How could I automate my use of lettrine, to make calls more or less like this:

  1. mylt {A}{l} more text

  2. mylt {Y} more text and correction of the disaster on this case

  3. mylt {1. }{C}{on} more text (here 1. is the content for "ante"

  4. mylt ****No idee how to manage the quotes and combine with csquotes

One Answer

I have been able to do it with the following command:

makeatletter
defltr{@ifnextchar[{@with}{@without}}
def@with[#1]#2{lettrine[findent=.3em, ante={#1}]{#2}}
def@without#1{lettrine[findent=.3em]{#1}}
makeatother

In this way I can simplify my use of lettrine, writing the following in the source code, according to the different cases exposed:

ltr {A}{b}

ltr [For ant=] {A}{b}

 ... etc

In the case of textquote{}, since it seemed complicated to my limited knowledge, I have chosen to put the type of opening and closing quotation mark directly in the text.

One example with the solution:

documentclass[ebook,8pt,twoside,openright,showtrims]{memoir}
usepackage{lipsum}
usepackage{xcolor}  
usepackage{lettrine}  
usepackage{csquotes} 

setulmarginsandblock{1.5cm}{1.5cm}{*}
setlrmarginsandblock{4cm}{1.5cm}{*}
checkandfixthelayout

renewcommand{LettrineFontHook}{color{red}}

newenvironment{body}{%
    addvspace{topsep}% Space above
}{%
    unskippar
    addvspace{topsep}% Space below
    %needspace{15baselineskip}
}

makeatletter
defltr{@ifnextchar[{@with}{@without}}
def@with[#1]#2{lettrine[findent=.3em, ante={#1}]{#2}}
def@without#1{lettrine[findent=.3em]{#1}}
makeatother

begin{document}
    
begin{body}        

ltr{A}{l} lipsum[1]                 %1. normal case

ltr{Y}{} lipsum[2]                  %2. case unique character (thanks @DG')

ltr[1. ]{C}{on} lipsum[3]           %3. case with "ante"

ltr[«]{Q}{uoted»} lipsum[4]         %4. case with quotes, the same solution for case 3

end{body}
            
end{document}

Output:

enter image description here

Answered by A. Cedano on March 16, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP