将用户定义的常量放入序言中

将用户定义的常量放入序言中

我认为这是一个可扩展内容的问题,我还没有完全掌握这个概念......

假设我有一个正在尝试配置的序言或 cls 文件hyperref。如果我已使用手动为作者设置了一个命令,\newcommand{\Me}{EngBIRD}那么我可以在配置文档属性时使用它,如下所示:

\hypersetup{
    pdfauthor={\Me},                % author
    pdfcreator={\Me},               % creator of the document
    pdfproducer={\Me}               % producer of the document
}

问题:在我创建的模板中,tex 文件只是一个模板。它链接到LaTeX_Personal_Details.autotex已在项目本地自动创建的 tex 文件(例如演示文件)中的内容。

\long\def\PersonalFirstName{I.}
\long\def\PersonalMiddleName{Eng}
\long\def\PersonalLastName{BIRD}
\long\def\PersonalPhoneNumber{Phone Number here}
\long\def\PersonalAddressLineOne{Street Address Here}
\long\def\PersonalAddressLineTwo{City, Province, Country Address Here}
\long\def\PersonalEmail{Email Here}

然后将该内容包含进去,并使用 MWE 将说明的定制设计命令来使用。

我尝试了许多命令定义(参见下面注释掉的行xparse),但我确信它们不起作用,因为超级设置中填充了一个未扩展的宏,该宏甚至还没有导入它的数据...我认为多次编译迭代可以解决顺序问题,所以我认为这是一个可扩展内容的问题......

有没有办法让我能够让存储在 pdf 属性中的用户信息由填充文档的相同数据驱动?我可能走在正确的轨道上,DeclareExpandableDocumentCommand但只是坚持最后一个参数不是可选的(当可以传递默认值并且不为空时,我也不明白这一点)?

\documentclass{article}

\usepackage{xparse}

    %\DeclareExpandableDocumentCommand{\Me}{ O{\PersonalFirstName} O{\PersonalMiddleName} O{\PersonalLastName} }{#1~#2~#3} % has potential, but doesn't compile with only optional arguments
    %\DeclareDocumentCommand{\Me}{ O{\PersonalFirstName} O{\PersonalMiddleName} O{\PersonalLastName} }{#1~#2~#3}
    %\def\Me#1{\gdef\@Me{#1}}
    %\Me{\PersonalFirstName~\PersonalMiddleName~\PersonalLastName}

    %\newcommand{\Me}{\PersonalFirstName~\PersonalMiddleName~\PersonalLastName}

    \newcommand{\Me}{EngBIRD}

    \DeclareDocumentCommand{\CustomTitleBlock}{ O{\PersonalFirstName} O{\PersonalMiddleName} O{\PersonalLastName} }
    {%
        {#1~#2~#3}
    }%

    \makeatletter   
    \DeclareDocumentCommand{\PersonalDataBlock}{ }
    {%
        {E-mail:}\PersonalEmail 

        {Phone:}\PersonalPhoneNumber

        {Address:}\PersonalAddressLineOne{,}\PersonalAddressLineTwo
    }%
    \makeatother    

%=========================================================================================================================================
% PACKAGES REQUIRED FOR HYPERLINKS AND HYPER-REFERENCES
%=========================================================================================================================================

    \usepackage{hyperref}
    \usepackage[noabbrev]{cleveref}

    \hypersetup{
        breaklinks=true,
        hypertexnames=false,
        %bookmarks=false,               % show bookmarks bar?
        unicode=true,                   % non-Latin characters in Acrobat's bookmarks
        pdftoolbar=true,                % show Acrobat's toolbar?
        pdfmenubar=true,                % show Acrobat's menu?
        pdffitwindow=true,              % window fit to page when opened
        pdfstartview={FitV},            % fits the height of the page to the window:  or fits the width of the page to the window  FitH
        pdftitle={CV - \Me},            % title
        pdfauthor={\Me},                % author
        %pdfsubject={Subject},          % subject of the document
        pdfcreator={\Me},               % creator of the document
        pdfproducer={\Me},              % producer of the document
        %pdfkeywords={keyword1} {key2} {key3}, % list of keywords
        pdfnewwindow=true,              % links in new window
        colorlinks=true,                % false: boxed links; true: colored links
        linkcolor=black,                % color of internal links (change box color with linkbordercolor)
        citecolor=black,                % color of links to bibliography
        filecolor=black,                % color of file links
        urlcolor=black                  % color of external links
    }

%--------------------BEGIN DOCUMENT----------------------
\begin{document}

%--------------------Load Data for Title and Contact information-------------
\input{LaTeX_Personal_Details.autotex}

%--------------------TITLE-------------
\CustomTitleBlock

%--------------------CONTACT INFORMATION-----------------------------------
\PersonalDataBlock

\end{document}

答案1

我认为你想生成

Title:          CV - I. Eng BIRD
Subject:        
Keywords:       
Author:         I. Eng BIRD
Creator:        I. Eng BIRD
Producer:       I. Eng BIRD
CreationDate:   Thu Mar 31 16:27:05 2016
ModDate:        Thu Mar 31 16:27:05 2016

我从

\documentclass{article}

\usepackage{xparse}

\input{LaTeX_Personal_Details.autotex}

\newcommand{\Me}{\PersonalFirstName\space\PersonalMiddleName\space\PersonalLastName}

    \DeclareDocumentCommand{\CustomTitleBlock}{ O{\PersonalFirstName} O{\PersonalMiddleName} O{\PersonalLastName} }
    {%
        {#1~#2~#3}
    }%

    \makeatletter   
    \DeclareDocumentCommand{\PersonalDataBlock}{ }
    {%
        {E-mail:}\PersonalEmail 

        {Phone:}\PersonalPhoneNumber

        {Address:}\PersonalAddressLineOne{,}\PersonalAddressLineTwo
    }%
    \makeatother    

%=========================================================================================================================================
% PACKAGES REQUIRED FOR HYPERLINKS AND HYPER-REFERENCES
%=========================================================================================================================================

    \usepackage{hyperref}
    \usepackage[noabbrev]{cleveref}

    \hypersetup{
        breaklinks=true,
        hypertexnames=false,
        %bookmarks=false,               % show bookmarks bar?
        unicode=true,                   % non-Latin characters in Acrobat's bookmarks
        pdftoolbar=true,                % show Acrobat's toolbar?
        pdfmenubar=true,                % show Acrobat's menu?
        pdffitwindow=true,              % window fit to page when opened
        pdfstartview={FitV},            % fits the height of the page to the window:  or fits the width of the page to the window  FitH
        pdftitle={CV - \Me},            % title
        pdfauthor={\Me},                % author
        %pdfsubject={Subject},          % subject of the document
        pdfcreator={\Me},               % creator of the document
        pdfproducer={\Me},              % producer of the document
        %pdfkeywords={keyword1} {key2} {key3}, % list of keywords
        pdfnewwindow=true,              % links in new window
        colorlinks=true,                % false: boxed links; true: colored links
        linkcolor=black,                % color of internal links (change box color with linkbordercolor)
        citecolor=black,                % color of links to bibliography
        filecolor=black,                % color of file links
        urlcolor=black                  % color of external links
    }

%--------------------BEGIN DOCUMENT----------------------
\begin{document}

%--------------------Load Data for Title and Contact information-------------


%--------------------TITLE-------------
\CustomTitleBlock

%--------------------CONTACT INFORMATION-----------------------------------
\PersonalDataBlock

\end{document}

相关内容