Libertine 和 lettrine 与 pdflatex:奇怪的错误

Libertine 和 lettrine 与 pdflatex:奇怪的错误

我有这个包lettrex.sty

\NeedsTeXFormat{LaTeX2e}
%
\RequirePackage{%
lettrine,%
ifthen,%
}
%
\setcounter{DefaultLines}{3}
\renewcommand{\DefaultLoversize}{0.07}
%
\DeclareOption{Libertine-Initials}{%
%X \renewcommand{\DefaultOptionsFile}{Libertine-Initials-Lettrinex.cfg}%
  \let\OldLettrine\lettrine%
  \renewcommand{\lettrine}[3][]{%
     \OldLettrine[#1]{\libertineInitialGlyph{#2}}{\MakeLowercase{#3}}%
  }%
}

\ProcessOptions\relax%
\endinput

和这个配置文件Libertine-Initials-Lettrinex.cfg

    \LettrineOptionsFor{A}{findent=-0.8em,nindent=0.5em,loversize=0.07,slope=0.6em}

当我编译时pdflatex testL-In.tex

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage{blindtext}

\usepackage[Libertine-Initials]{lettrex}

\begin{document}
\lettrine{A}{is a letter of our alphabet}. \blindtext
\end{document}

然后一切似乎都正常。但是当我删除%Xinlettrex.sty以启用字母“A”的选项时,我收到此错误:

(./testL-In.aux) (./Libertine-Initials-Lettrinex.cfg)
! Missing \endcsname inserted.
<to be read again> 
                   \protect 
l.16 \lettrine{A}{is a letter of our alphabet}
                                              . \blindtext
? 

(/zfs/texlive/2022/texmf-dist/tex/latex/libertine/T1LinuxLibertineInitialsT-LF.
fd)
! Extra \endcsname.
\@lettrine ...er \ifx \csname l@#2-keys\endcsname 
                                                  \relax \gdef \l@LOKeys {}\...
l.16 \lettrine{A}{is a letter of our alphabet}
                                              . \blindtext
? 

Overfull \hbox (7.46712pt too wide) in paragraph at lines 16--17
[][]\T1/LinuxLibertineT-TLF/m/n/12 . Lorem ip-sum do-lor sit amet, con-sectetue
r
[1{/zfs/texlive/2022/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
(./testL-In.aux) ){/zfs/texlive/2022/texmf-dist/fonts/enc/dvips/libertine/lbtn_
ncsllp.enc}{/zfs/texlive/2022/texmf-dist/fonts/enc/dvips/libertine/lbtn_vsrqlo.
enc}{/zfs/texlive/2022/texmf-dist/fonts/enc/dvips/libertine/lbtn_76gpa5.enc}</z
fs/texlive/2022/texmf-dist/fonts/type1/public/libertine/LinLibertineIT.pfb></zf
s/texlive/2022/texmf-dist/fonts/type1/public/libertine/LinLibertineT.pfb>
Output written on testL-In.pdf (1 page, 119263 bytes).
Transcript written on testL-In.log.

最后它确实给了我初始值,但这里做错了什么?

答案1

无需 patch \lettrine,可以使用 lettrine 提供的钩子:

\begin{filecontents}{Libertine-Initials-Lettrinex.cfg}
\LettrineOptionsFor{A}{findent=-0.8em,nindent=0.5em,loversize=0.07,slope=0.6em}
\end{filecontents}

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage{blindtext}

\usepackage[optionsfile=Libertine-Initials-Lettrinex.cfg]{lettrine}
\renewcommand\LettrineFontHook{\libertineInitial}
\renewcommand\LettrineTextFont{\MakeLowercase}
\begin{document}

\lettrine{A}{IS A LETTER OF OUR ALPHABET}. %uppercase for demo
\blindtext
\end{document}

在此处输入图片描述

答案2

问题是第二个参数用于检查特定的首字母是否与文件中的某些代码相关联.cfg,并且传递它\libertineInitialGlyph{<letter>}会中断。

您需要修补其他内容,即\setupL@lbox存储排版首字母的位置。

我认为您并不真正想要\MakeLowercase第二个论点。

\NeedsTeXFormat{LaTeX2e}

\RequirePackage{lettrine}

\setcounter{DefaultLines}{3}
\renewcommand{\DefaultLoversize}{0.07}

\DeclareOption{Libertine-Initials}{%
  \renewcommand{\DefaultOptionsFile}{Libertine-Initials-Lettrinex.cfg}%
  \def\setupL@lbox{%
    \computeL@height
    \ifL@image
      \sbox{\L@lbox}{\LettrineImage{\l@initial}}%
    \else
      \compute@fontsize
      \sbox{\L@lbox}{\LettrineFont\libertineInitialGlyph{\l@initial}}%
    \fi
  }%
}

\ProcessOptions\relax

\endinput

在此处输入图片描述

也许您可以删除\LettrineFont

答案3

您不需要修补任何内容,只需更改文件lettrex.sty

\begin{filecontents}{Libertine-Initials.cfg}
\LettrineOptionsFor{A}{findent=-0.8em,
    nindent=0.5em,loversize=0.07,slope=0.6em}
\end{filecontents}

\begin{filecontents}{lettrex.sty}
\NeedsTeXFormat{LaTeX2e}

\RequirePackage{%
  lettrine,%
  iftex,%
}

\setcounter{DefaultLines}{3}
\renewcommand{\DefaultLoversize}{0.07}

\DeclareOption{Libertine-Initials}{%
\renewcommand{\LettrineFontHook}{%
              \fontfamily{LinuxLibertineInitialsT-LF}}
\renewcommand{\DefaultOptionsFile}{Libertine-Initials.cfg}
}
\ifpdftex
  \DeclareOption{Libertine-Initials}{%
  \renewcommand\LettrineFontHook{%
               \fontfamily{LinuxLibertineInitialsT-LF}}
  \renewcommand{\DefaultOptionsFile}{Libertine-Initials.cfg}
  }
\else
  \DeclareOption{Libertine-Initials}{%
  \renewcommand\LettrineFontHook{\fontspec{LinLibertine_I.otf}}
  \renewcommand{\DefaultOptionsFile}{Libertine-Initials.cfg}
 }
\fi

\ProcessOptions\relax
\endinput
\end{filecontents}

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage{blindtext}
\usepackage[Libertine-Initials]{lettrex}

\begin{document}
\lettrine{A}{is a letter of our alphabet}. \blindtext
\end{document}

不产生任何错误消息并输出

在此处输入图片描述

如果你不想在第二个参数中使用小写字母\lettrine,只需添加 \renewcommand{\LettrineTextFont}{\relax}

相关内容