假小写字母

假小写字母

我用了一个我在 StackExchange 上找到的伪造小型大写的脚本

\documentclass{report}

% Source: https://tex.stackexchange.com/a/262596/146754
\usepackage{xstring} % needed for IfEqCase
\usepackage{forloop}
\usepackage{relsize}

\newcommand{\fakescsize}{0.75}

\newcounter{sccounter}
\newcounter{tempStringLength}

\newcommand{\FakeSmallCaps}[1]{%
    % this \betterfakesc command requires these two packages:
    %   xstring
    %   forloop
    %
    % First, we obtain the length of the input string.
    \StrLen{#1}[\stringLength]%
    %
    % Our main forloop will be using a condition of “while less than \stringLength”,
    % so we’ll need to increase \stringLength by 1 so the forloop will be able to iterate 
    % over the entire string. we’ll use a temporary counter tempStringLength to make
    % this increase. That’s what the next three lines are about.
    \setcounter{tempStringLength}{\stringLength}%
    \addtocounter{tempStringLength}{1}%
    \def\stringLength{\arabic{tempStringLength}}%
    %
    % Here is our main loop. We iterate over the characters in the input string,
    % and the currentLetter is compared to the case rules we have defined. Basically
    % if the currentLetter is any of the lowercase a-z letters, then we apply a 
    % “fake small caps” effect to it and output it.
    \forloop[1]{sccounter}{1}{\value{sccounter}<\stringLength}{%
        \StrChar{#1}{\value{sccounter}}[\currentLetter]%
        %
        \IfEqCase*{\currentLetter}{%
            % The lines below are the rules. Obviously more could be added.
            {a}{{\relscale{\fakescsize}{A}}}%
            {b}{{\relscale{\fakescsize}{B}}}%
            {c}{{\relscale{\fakescsize}{C}}}%
            {d}{{\relscale{\fakescsize}{D}}}%
            {e}{{\relscale{\fakescsize}{E}}}%
            {f}{{\relscale{\fakescsize}{F}}}%
            {g}{{\relscale{\fakescsize}{G}}}%
            {h}{{\relscale{\fakescsize}{H}}}%
            {i}{{\relscale{\fakescsize}{I}}}%
            {j}{{\relscale{\fakescsize}{J}}}%
            {k}{{\relscale{\fakescsize}{K}}}%
            {l}{{\relscale{\fakescsize}{L}}}%
            {m}{{\relscale{\fakescsize}{M}}}%
            {n}{{\relscale{\fakescsize}{N}}}%
            {o}{{\relscale{\fakescsize}{O}}}%
            {p}{{\relscale{\fakescsize}{P}}}%
            {q}{{\relscale{\fakescsize}{Q}}}%
            {r}{{\relscale{\fakescsize}{R}}}%
            {s}{{\relscale{\fakescsize}{S}}}%
            {t}{{\relscale{\fakescsize}{T}}}%
            {u}{{\relscale{\fakescsize}{U}}}%
            {v}{{\relscale{\fakescsize}{V}}}%
            {w}{{\relscale{\fakescsize}{W}}}%
            {x}{{\relscale{\fakescsize}{X}}}%
            {y}{{\relscale{\fakescsize}{Y}}}%
            {z}{{\relscale{\fakescsize}{Z}}}%
        }%
        % if our \currentLetter isn’t any of the letters we have rules for,
        % then just output it now
        [{\currentLetter}]%
    }%
}

\newcommand{\TitleTest}{Hello}

\begin{document}

\section{\TitleTest}

Lorem \FakeSmallCaps{Ipsum} is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

\let\OldTitleTest\TitleTest
\renewcommand{\TitleTest}{\FakeSmallCaps{\OldTitleTest}}

\section{\TitleTest}

It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.

\end{document}

为什么在顶部可以运行,但在底部却不行?为什么我在第 86 行出现以下错误?

    Runaway argument?
    Runaway argument?
    Illegal parameter number in definition of \reserved@a.
    Argument of \xs_IfStringCase_ii has an extra }.
    Runaway argument?
    Argument of \xs_reserved_A has an extra }.
    Runaway argument?
    Argument of \xs_readdecimalpart has an extra }.
    Undefined control sequence.

在此处输入图片描述

答案1

首先:如果您想要小型大写字母,请选择具有真正小型大写字母的字体系列。

如果您更喜欢糟糕的排版,至少要使用更好的方法来伪造小型大写字母。

\RequirePackage{fix-cm} % just for this example
\documentclass{article}
\usepackage{relsize}

\newcommand{\fakescsize}{0.75}

\ExplSyntaxOn

\NewDocumentCommand{\fakesc}{m}
 {
  \stucke_fakesc:e { \text_expand:n { #1 } }
 }

\cs_new_protected:Nn \stucke_fakesc:n
 {
  \tl_set:Nn \l_tmpa_tl { #1 }
  \regex_replace_all:nnN
   { [a-z]+ } % any run of lowercase letters
   { \c{__stucke_fakesc_do:n}\cB\{\0\cE\} } % enclose as argument
   \l_tmpa_tl
  \tl_use:N \l_tmpa_tl
 }
\cs_generate_variant:Nn \stucke_fakesc:n { e }

\cs_new_protected:Nn \__stucke_fakesc_do:n
 {
  \relscale{\fakescsize}{\text_uppercase:n { #1 } }
 }

\ExplSyntaxOff

\begin{document}

\newcommand{\TitleTest}{Hello}

\section{\fakesc{Hello}}
\section{\fakesc{\TitleTest}}

\end{document}

在此处输入图片描述

相关内容