Egreg 对这个问题的精彩回答执行 expl3 中键值中给出的宏在以前的代码中集成时不起作用。这是我的标题出现在测试中,但并未转化。
docvar.sty
到目前为止,包 ( ) 看起来是这样的:
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{docvar}
[2017/02/16 v1.00 Define, manage and use document variables.]
\RequirePackage{xparse}
\ExplSyntaxOn
\prop_new:N \g_docvar_defined_prop
\prop_new:N \g_docvar_values_prop
\prop_new:N \g_docvar_inheritance_prop
\prop_new:N \g_docvar_transform_prop
\tl_new:N \l_docvar_transformation_tl
\tl_new:N \l_docvar_temp_tl
\DeclareDocumentCommand \definedocvar {o m} {
\IfNoValueF { #1 }
{
\docvar_definition_properties:n {#1} {#2}
}
\prop_gput_if_new:Nnn \g_docvar_defined_prop {#2} {}
}
\tl_new:N \l_docvar_inherit_tl
\keys_define:nn { docvar/define }
{
inherit .tl_set:N = \l_docvar_inherit_tl,
}
\cs_new_protected:Npn \docvar_definition_properties:n #1 #2
{
\group_begin:
\keys_set:nn { docvar/define } { #1 }
\tl_if_empty:NF \l_docvar_inherit_tl
{
\prop_gput:NnV \g_docvar_inheritance_prop {#2} \l_docvar_inherit_tl
}
\group_end:
}
\prg_new_conditional:Npnn \docvar_key_defined:n #1 {p, T, F, TF}
{
\prop_if_in:NnTF \g_docvar_defined_prop {#1} {\prg_return_true:} {\prg_return_false:}
}
\DeclareDocumentCommand \setdocvar {m m}{
\prop_gput:Nnn \g_docvar_values_prop {#1} {#2}
}
\keys_define:nn { docvar/get }
{
transform .tl_set:N = \l_docvar_tranformation_tl,
transform .initial:n = \use:n,
}
\cs_new_protected:Npn \docvar_get_properties:n #1
{
\keys_set:nn { docvar/get } { #1 }
}
\cs_new_protected:Nx \__docvar_transform:nn
{
\typeout{in~transfrom}
\tl_show:N \l_docvar_temp_tl
\tl_set:Nn \l_docvar_temp_tl {#1{#2}}
\tl_show:N \l_docvar_temp_tl
\typeout{out~transfrom}
}
\cs_generate_variant:Nn \__docvar_transform:nn { VV }
\DeclareDocumentCommand \getdocvar {o m}{
\group_begin:
\IfNoValueF { #1 }
{
\docvar_get_properties:n {#1}
\tl_show:N \l_docvar_tranformation_tl
}
\prop_if_in:NnTF \g_docvar_values_prop {#2}
{
\tl_set:Nn \g_tmpb_tl {#2}
}
{
\prop_if_in:NnTF \g_docvar_inheritance_prop {#2}
{
\prop_get:NnN \g_docvar_inheritance_prop {#2} \g_tmpb_tl
}
{
%TODO print message or empty value
}
}
\prop_get:NVN \g_docvar_values_prop \g_tmpb_tl \g_tmpa_tl
\tl_show:N \g_tmpa_tl
\__docvar_transform:VV \l_docvar_transformation_tl \g_tmpa_tl
\tl_use:N \l_docvar_temp_tl
\group_end:
}
\ExplSyntaxOff
还有一个测试文件testminimal.lvt
\documentclass{minimal}
\input{regression-test}
\usepackage{docvar}
\begin{document}
\START
\definedocvar{title}
\setdocvar{title}{This is the long title}
Using a docvar directly:
\getdocvar{title}
Using a docvar that is inhereting:
\definedocvar[inherit=title]{subtitle}
\getdocvar{subtitle}
dovar retrieved with tranformation
\getdocvar[transform=\MakeUppercase]{title}
\showoutput
\end{document}
我不明白为什么它不起作用。