我有一些条件存储在布尔变量中,例如
\bool_new:N \l_word_numbered_bool
\bool_new:N \l_word_lowercase_bool
\bool_new:N \l_word_centering_bool
我需要以最简单的方式根据布尔变量的值来格式化单词(或段落)。
首先想到的是使用 many \bool_if:NTF
-s 但我认为应该有一种更简单的方法。
我的最终目标是创建该部分的自定义视图。
平均能量损失
\documentclass[12pt]{article}
\usepackage{expl3, xtemplate,xparse}
\ExplSyntaxOn
\DeclareObjectType { sectioning } { 1 }
\DeclareTemplateInterface{sectioning}{section}{1}
{
numbered : boolean = true ,
space-above : length = 2ex ,
space-below : length = 2ex ,
font-shape : choice {italic, slanted, normal} = normal,
lowercase : choice {true, false} = true,
centering : choice{true, false} = false,
font-weight : choice {bold, normal} = bold,
font-color : tokenlist,
font-size : length = 12pt,
%font-face : tokenlist,
}
% the interface for the template `initial':
% variables first:
\bool_new:N \l_sectioning_numbered_bool
\dim_new:N \l_sectioning_space_above_dim
\dim_new:N \l_sectioning_space_below_dim
\bool_new:N \l_sectioning_lowercase_bool
\bool_new:N \l_sectioning_centering_bool
\dim_new:N \l_font_size_dim
\DeclareTemplateCode {sectioning} {section} {1}
{
numbered = \l_sectioning_numbered_bool ,
font-size = \l_font_size_dim,
lowercase = {
true = \bool_set_true:N \l_sectioning_lowercase_bool,
false = \bool_set_false:N \l_sectioning_lowercase_bool,
},
centering = {
true = \bool_set_true:N \l_sectioning_centering_bool,
false = \bool_set_false:N \l_sectioning_centering_bool,
},
space-above = \l_sectioning_space_above_dim ,
space-below = \l_sectioning_space_below_dim ,
font-shape = {
italic = \cs_set_nopar:Nn \afontshape: {\itshape},
slanted = \cs_set_nopar:Nn \afontshape: {\itshape},
normal = \cs_set_nopar:Nn \afontshape: {\upshape},
},
font-weight = {
bold = \cs_set_nopar:Nn \afontseries: {\bfseries},
normal = \cs_set_nopar:Nn \afontseries: {\rmfamily},
},
%font-face = \l_font_tl,
font-color = \l_tmpa_tl,
}
{
\AssignTemplateKeys
\vskip\l_sectioning_space_above_dim
\group_begin:
\color\l_tmpa_tl
%\cs:w \l_font_tl \cs_end:
\fontsize{\l_font_size_dim}{\l_font_size_dim}\afontseries:\afontshape:\selectfont
\bool_if:NTF \l_sectioning_lowercase_bool {
\bool_if:NTF \l_sectioning_numbered_bool {\thesection.\, \tl_to_lowercase:n {#1}}{\tl_to_lowercase:n {#1}}
}
{
\bool_if:NTF \l_sectioning_numbered_bool {\thesection.\, \tl_to_uppercase:n {#1}}{\tl_to_uppercase:n {#1}}
}
\group_end:
\addtocounter{section}{1}
\vskip\l_sectioning_space_below_dim
}
% a few instances, starting with `fullname':
\DeclareInstance {sectioning}{standart}{section}
{
numbered = true,
font-shape = italic,
font-weight = bold,
lowercase = true,
space-below = 2em,
%font-face = arial,
font-size = 12 pt
}
% the user command:
\DeclareDocumentCommand \sectant{m}
{
\UseInstance{sectioning}{standart}{#1}
}
\ExplSyntaxOff
\begin{document}
\sectant{Something}
\end{document}
取决于
\DeclareInstance {sectioning}{standart}{section}
{
numbered = false,
font-shape = italic,
font-weight = bold,
lowercase = false,
space-below = 2em,
%font-face = arial,
}
我期望所需的格式。我的 MWE 是可行的,但正如您在下面看到的,检查代码的大小写\sectant{Something}
部分看起来非常糟糕。upper/lower
numbered/unnumbered
\bool_if:NTF \l_sectioning_lowercase_bool {
\bool_if:NTF \l_sectioning_numbered_bool {\thesection.\, \tl_to_lowercase:n {#1}}{\tl_to_lowercase:n {#1}}
}
{
\bool_if:NTF \l_sectioning_numbered_bool {\thesection.\, \tl_to_uppercase:n {#1}}{\tl_to_uppercase:n {#1}}
}
答案1
\bool_if:NT \l_sectioning_numbered_bool { \thesection.\ }
\bool_if:NTF \l_sectioning_lowercase_bool
{ \text_lowercase:n } { \text_uppercase:n } { #1 }
在这种情况下,我认为这就足够了。可能更清楚的是
\bool_if:NT \l_sectioning_numbered_bool { \thesection.\ }
\bool_if:NTF \l_sectioning_lowercase_bool
{ \text_lowercase:n { #1 } }
{ \text_uppercase:n { #1 } }
最后一个布尔值,可以在其他情况下使用,甚至可以完成(注意,我缩短了名称以使其适合一行)
\use:c { text_ \bool_if:NTF \l_sect_lower_bool { lower } { upper } case:n } { #1 }
我发现你没有做的一件事是将“包”的名称添加到你的定义中。例如,他们可以携带sk
(sergiokapone)
\bool_new:N \l_sk_sectioning_numbered_bool
\dim_new:N \l_sk_sectioning_space_above_dim
\dim_new:N \l_sk_sectioning_space_below_dim
\bool_new:N \l_sk_sectioning_lowercase_bool
\bool_new:N \l_sk_sectioning_centering_bool
\dim_new:N \l_sk_font_size_dim