我希望有两个命令来减少文档中用于管理字母大写的代码。第一个命令应该像普通小写字母一样工作;但第二个命令应该使用斜体形状。有没有办法定义宏,让我可以在序言之后使用,并改变lettrine
使用的字体?
最小代码示例:
\documentclass{scrartcl}
\usepackage{xltxtra}
\usepackage{xcolor} % für farbigen Text
\setromanfont[SmallCapsFont={Alegreya Sans SC}]{Alegreya Sans}
\usepackage{lettrine}
\renewcommand{\LettrineFontHook}{%
\fontseries{\seriesdefault}
\fontshape{\shapedefault}
}
\renewcommand{\LettrineFontHook}{%
\fontfamily{\familydefault}
\fontseries{\seriesdefault}
\fontshape{\itdefault}
\selectfont
}
\newcommand{\LettrineA}[2]{\lettrine[lines=3,findent=.5em]{\color{olive}#1}{#2}}
\newcommand{\LettrineB}[2]{\lettrine[lines=3,findent=.5em]{\color{orange}#1}{#2}}
\begin{document}
\LettrineA{T}{his text} is written in a normal font. The first 2 words are in small caps. The following words are only here to fill the paper and waste some space, time and hopefully no money. But if it is wasting time it is wasting money aswell if we trust old phrases.
\LettrineB{T}{his text} is written in a normal font. The first 2 words are in italic shape. The following words are only here to fill the paper and waste some space, time and hopefully no money. But if it is wasting time it is wasting money aswell if we trust old phrases.
\end{document}
答案1
这是一个\FlexibleLettrine
宏,您可以为 设置比平常更多的参数\lettrine
。然后您可以根据此定义\LettrineA
和。\LettrineB
请注意,如果您希望小型大写字体遵循字体更改命令,则必须加载 Alegreya Sans。
\documentclass{scrartcl}
\usepackage{fontspec}
\usepackage{xcolor} % für farbigen Text
\usepackage{lettrine}
\setmainfont{Alegreya Sans}[
UprightFeatures={SmallCapsFont=* SC},
ItalicFeatures={SmallCapsFont=* SC Italic},
BoldFeatures={SmallCapsFont=* SC Bold},
BoldItalicFeatures={SmallCapsFont=* SC Bold Italic},
]
\newcommand{\FlexibleLettrine}[5][]{%
% #1 = options to \lettrine
% #2 = font for lettrine
% #3 = font for the following word parts
% #4 = lettrine
% #5 = following word parts
\begingroup
\renewcommand{\LettrineFontHook}{\normalfont#2}%
\lettrine[#1]{#4}{\normalfont#3#5}%
\endgroup
}
\newcommand{\LettrineA}[2]{%
\FlexibleLettrine[lines=3,findent=.5em]
{\normalfont}
{\scshape}
{\color{olive}#1}
{#2}%
}
\newcommand{\LettrineB}[2]{%
\FlexibleLettrine[lines=3,findent=.5em]
{}
{\scshape\itshape}
{\color{orange}#1}
{#2}%
}
\newcommand{\LettrineC}[2]{%
\FlexibleLettrine[lines=3,findent=.5em]
{\itshape}
{\itshape}
{\color{orange}#1}
{#2}%
}
\newcommand{\LettrineD}[2]{%
\FlexibleLettrine[lines=3,findent=.5em]
{}
{\itshape}
{\color{orange}#1}
{#2}%
}
\begin{document}
\LettrineA{T}{his text} is written in a normal font.
The first 2 words are in small caps. The following
words are only here to fill the paper and waste some
space, time and hopefully no money. But if it is wasting
time it is wasting money aswell if we trust old phrases.
\LettrineB{T}{his text} is written in a normal font.
The first 2 words are in small caps italic shape. The following
words are only here to fill the paper and waste some
space, time and hopefully no money. But if it is wasting
time it is wasting money aswell if we trust old phrases.
\LettrineC{T}{his text} is written in a normal font.
The first 2 words are in italic shape. The following
words are only here to fill the paper and waste some
space, time and hopefully no money. But if it is wasting
time it is wasting money aswell if we trust old phrases.
\LettrineD{T}{his text} is written in a normal font.
The first 2 words are in italic shape. The following
words are only here to fill the paper and waste some
space, time and hopefully no money. But if it is wasting
time it is wasting money aswell if we trust old phrases.
\end{document}
顺便说一句,xltxtra
现在不推荐使用加载,并且\setromanfont
已被弃用。
答案2
你想要这样的东西吗?这样你就可以这么说
\lettrinea
并\lettrine
会给出一个橄榄形、直立的字母,后面跟着小写字母,或者
\lettrineb
并将lettrine
显示一个橙色的斜体字母,后面跟着斜体。
\documentclass{scrartcl}
\usepackage{xcolor} % für farbigen Text
\usepackage{fontspec}
\setromanfont[SmallCapsFont={Alegreya Sans SC}]{Alegreya Sans}
\usepackage{lettrine}
\newcommand*\lettrinea{%
\renewcommand*{\LettrineFontHook}{\normalfont\color{olive}}%
\renewcommand*\LettrineTextFont{\normalfont\scshape}%
\setlength\DefaultFindent{.5em}%
\setcounter{DefaultLines}{3}%
}
\newcommand*\lettrineb{%
\renewcommand{\LettrineFontHook}{\normalfont\itshape\color{orange}}%
\renewcommand*\LettrineTextFont{\normalfont\itshape}%
\setlength\DefaultFindent{.5em}%
\setcounter{DefaultLines}{3}%
}
\begin{document}
\lettrinea
\lettrine{T}{his text} is written in a normal font. The first 2 words are in small caps. The following words are only here to fill the paper and waste some space, time and hopefully no money. But if it is wasting time it is wasting money aswell if we trust old phrases.
\lettrineb
\lettrine{T}{his text} is written in a normal font. The first 2 words are in italic shape. The following words are only here to fill the paper and waste some space, time and hopefully no money. But if it is wasting time it is wasting money aswell if we trust old phrases.
\end{document}