Preestableciendo claves xkeyval en \thetitle o \theauthor

Preestableciendo claves xkeyval en \thetitle o \theauthor

Estoy escribiendo una plantilla LaTeX y casi termino (!!!) pero me cuesta mucho entender xkeyvalel \presetkeyscomportamiento. Logré establecer algunos valores predeterminados, pero cuando se trata de configurarlos \theauthor, \thetitlelas claves se configuran en cadenas vacías a pesar de que están configuradas después de los comandos \author{}y .\title{}

Aquí hay un mwe:

mi_mwe.cls

\RequirePackage{expl3}

\ProvidesExplClass{my_mwe}
                  {2020/09/08}
                  {1.0}
                  {Minimal working example}

\LoadClass{report}

\RequirePackage{xkeyval}
\RequirePackage{xparse}

\AtBeginDocument{%
    \define@key{my_mwe} {author} [] {\def\my_mwe@author{#1}}
    \define@key{my_mwe} {title}  [] {\def\my_mwe@title{#1}}
    \presetkeys{my_mwe} {author}    {author={\theauthor}}
    \presetkeys{my_mwe} {title}     {title=\thetitle}
}

\NewDocumentCommand{\MWECommand}{O{}}{%
    \setkeys{my_mwe}{author, title, #1}%

    Here's~the~output:\\
    \my_mwe@title \\
    \my_mwe@author
}

mwe.tex

\documentclass[10pt, a4paper]{my_mwe}

\usepackage{titling}
    \author{The poor crying author}
    \title{A sad mwe}

\begin{document}

\MWECommand%

\MWECommand[title=\thetitle, author=\theauthor]

\end{document}

Lo que espero es que la llamada básica MWECommandhaga lo mismo que la argumentada, pero en cambio las cadenas \theauthory \thetitlesolo se imprimen en la segunda. ¿Qué estoy haciendo mal?

Respuesta1

Estás configurando explícitamente el valor predeterminado, que se usa si pasas las claves authoro titlesin un valor, para que esté vacío con

\define@key{my_mwe}{author}[]{\def\my_mwe@author{#1}}

El valor especificado entre paréntesis sería el predeterminado (que en este caso está vacío). La \presetkeysmacro establece un valor inicial, es decir, un valor que se utilizará si la clave no se establece explícitamente.

Ahora en su macro usted ingresa author, title, #1su \setkeys, por lo que se usarán los valores predeterminados, no los iniciales. Y los valores predeterminados están vacíos.

Entonces, la forma más fácil sería eliminar author, titlede su definición (también eliminé la línea vacía en la definición, ya que dudo que quiera tener \parallí, cuál sería el resultado):

\RequirePackage{expl3}

\ProvidesExplClass{my_mwe}
                  {2020/09/08}
                  {1.0}
                  {Minimal working example}

\LoadClass{report}

\RequirePackage{xkeyval}
\RequirePackage{xparse}

\AtBeginDocument{%
    \define@key{my_mwe} {author} [] {\def\my_mwe@author{#1}}
    \define@key{my_mwe} {title}  [] {\def\my_mwe@title{#1}}
    \presetkeys{my_mwe} {author}    {author={\theauthor}}
    \presetkeys{my_mwe} {title}     {title=\thetitle}
}

\NewDocumentCommand{\MWECommand}{O{}}{%
    \setkeys{my_mwe}{#1}%
    Here's~the~output:\\
    \my_mwe@title \\
    \my_mwe@author
}

información relacionada