将 xparse 变量设置为小写

将 xparse 变量设置为小写

前段时间,我问过如何轻松定义多个变量,最好的答案是xparse及其对keyvalue我现在有两个相关问题,我想在这里讨论一下。

笔记:检查一下可能很有用原始帖子继续之前,请先了解我的xparse设置。


问题 1

\lowercase{}我现在尝试在这些“变量”上使用该函数。

\lowercase{\GetInvoiceData{FirstName}}

这会产生输出Unknown,如果我只是调用\GetInvoiceData{FirstName},一切都会正常工作。

所以我的问题是,如何以小写形式打印键的值xparse


问题 2

我添加了%Christian Hupfer 在评论中提出的建议,解决了这个问题。

此外,我想将我的整个名字以小写字母打印出来并连接在一起(第一个名字用细字体,第二个名字用粗体字体),如下所示:

约翰母鹿

我当前的代码如下所示

\newcommand{\headertext}[2]
{%
    \color{white}%
    {%
        \Huge{%
            %\lowercase{%
                \textlight{#1}\textbold{#2}%
            %}%
        }%
    }%
}

% later in the code

\headertext{\GetInvoiceData{FirstName}}{\GetInvoiceData{SecondName}}

请注意,\textlight{}\textbold{}定义应该使用哪种字体:

\newcommand{\textlight}[1]
{%
    % Normally defines another font
    {#1}
}
% Same for \textbold{}

如您所见,\lowercase{}由于Unknown-issue,目前已被注释掉,但其输出为:

约翰多伊

因此字体选择工作正常,但为什么两个值之间有一个空格?我该如何去掉它?


平均能量损失

\documentclass{article}

%% %%%%%%%%%%%%%%%%%%%%%%%
%% Variables Configuration
%% %%%%%%%%%%%%%%%%%%%%%%%

\RequirePackage{xparse}

\ExplSyntaxOn

    \prop_new:N \g_invoice_prop
    
    \cs_new:Nn \invoice_store_property:nn {
        \prop_gput:Nnn \g_invoice_prop {#1} {#2}
    }
    
    %Defining key-value interface
    \keys_define:nn {invoice} {
        FirstName       .code:n = {\invoice_store_property:nn {FirstName}{#1} },
        LastName        .code:n = {\invoice_store_property:nn {LastName}{#1} },
    }
      
    \NewDocumentCommand{\StoreInvoiceData}{+m}{
        \prop_gclear:N \g_invoice_prop% Clearing the property list
        % Set the keys
        \keys_set:nn {invoice}{#1}
    }
    
    \NewDocumentCommand{\GetInvoiceData}{m}{
        \prop_if_in:NnTF \g_invoice_prop {#1} 
        {% True
            \prop_item:Nn \g_invoice_prop {#1}% Extract the key #1 from the property list
        }{% False
            Unknown
        }
    }

    % Check if the field is given and execute #2 for true case, otherwise #3
    \NewDocumentCommand{\IfInvoiceFieldGivenTF}{m+m+m}{%
        \prop_if_in:NnTF \g_invoice_prop {
            #1% Check to check
        }{% True #2
            #2
        }{% False
            #3
        }
    }% End of \IfInVoiceFieldGivenT
    
    % Do something only if #1 is given 
    \NewDocumentCommand{\IfInvoiceFieldGivenT}{m+m}{%
        \prop_if_in:NnT \g_invoice_prop {
            #1% Check to check
        }{% True #2
            #2
        }%
    }% End of \IfInVoiceFieldGivenT

\ExplSyntaxOff

\StoreInvoiceData{
    FirstName   =   {John},
    LastName    =   {Doe},
}



%% %%%%%%%%%%%%%%%%%%
%% Font Configuration
%% %%%%%%%%%%%%%%%%%%

\newcommand{\textlight}[1]
{%
    % Normally defines another font
    {#1}%
}

\newcommand{\textbold}[1]
{%
    % Normally defines another font
    {\bfseries#1}%
}

\newcommand{\headertext}[2]
    {%
        \color{black}
        {%
            \Huge{%
                \lowercase{%
                    \textlight{#1}\textbold{#2}
                }
            }
        }
    }
    
    
\begin{document}
    \headertext{\GetInvoiceData{FirstName}}{\GetInvoiceData{LastName}}
\end{document}

注释掉\lowercase{}后,您会看到名称已正确打印。使用该函数时,它仅打印Unknown

相关内容