In this thread, writing newcommands, user interface advice request, some of you taught me how to write a function that can generate an elaborate header.
In that case, my problem was complicated because the number of authors in the document could be more than 1. We planned out an approach for 3 authors, but the strategy is very cumbersome. It is necessary to insert new stanzas and conditionals for additional authors. You taught me how to do that, and it works, and I am grateful for the effort.
Output I currently get looks like this:
Author wants to be able to easily exclude the "Guide No", "Keywords" and "url" sections. Their suggestion is to just leave blank fields, or even omit keys from document function call.
I want you to tell me how to make this more flexible.
Following the twoauthors and threeauthors example from last time, I need to create a bool for each one and then conditionalize the output. I fiddled around with the syntax and did not get it to work. But, even if I could make that work, I can't quite believe it is the best way. It is so tedious.
Here's the document that generates above MRE:
\documentclass[11pt,letterpaper,english]{extarticle}
\usepackage{lmodern}
\renewcommand{\sfdefault}{lmss}
\renewcommand{\ttdefault}{lmtt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[demo]{graphicx}
\usepackage[includehead, includefoot,
lmargin=1in,
rmargin=1in,
tmargin=0.75in,
bmargin=1.0in,
headheight=0pt,
headsep=0pt,
marginparwidth=0pt,
footskip=1.5\baselineskip,
]{geometry}
\usepackage{xcolor}
\definecolor{darkblue}{HTML}{1e2277}
% $ This nullifies emacs subscripting in following%
%%BEGIN: This begins the custom header
\usepackage{array, tabularx}
\usepackage{xparse}
\usepackage{datetime}
\usepackage[unicode=true,pdfusetitle,
bookmarks=true,bookmarksnumbered=false, bookmarksopen=false,
breaklinks=true, pdfborder={0 0 0},
pdfborderstyle={}, backref=false,
colorlinks=true, linkcolor=darkblue, urlcolor=darkblue,
citecolor=darkblue] {hyperref}
\newdateformat{crmda}{\small{}\textbf{\shortmonthname[\THEMONTH] \THEDAY, \THEYEAR}}
\ExplSyntaxOn
\NewDocumentCommand \guidesetup { +m }
{
\bool_set_false:N \l_guide_twoauthors_bool
\bool_set_false:N \l_guide_threeauthors_bool
\keys_set:nn { guide } { #1 }
}
\keys_define:nn { guide }
{
firstauthor .code:n = {
\keys_set:nn { guide / firstauthor } { #1 }
},
secondauthor .code:n = {
\keys_set:nn { guide } { twoauthors }
\keys_set:nn { guide / secondauthor } { #1 }
},
thirdauthor .code:n = {
\keys_set:nn { guide } { threeauthors }
\keys_set:nn { guide / thirdauthor } { #1 }
},
twoauthors .bool_set:N = \l_guide_twoauthors_bool,
twoauthors .default:n = true,
twoauthors .initial:n = false,
threeauthors .bool_set:N = \l_guide_threeauthors_bool,
threeauthors .default:n = true,
threeauthors .initial:n = false,
firstauthor / firstname .tl_set:N = \l_guide_first_firstname_tl,
firstauthor / lastname .tl_set:N = \l_guide_first_lastname_tl,
firstauthor / affiliation .tl_set:N = \l_guide_first_affil_tl,
firstauthor / email .tl_set:N = \l_guide_first_email_tl,
secondauthor / firstname .tl_set:N = \l_guide_second_firstname_tl,
secondauthor / lastname .tl_set:N = \l_guide_second_lastname_tl,
secondauthor / affiliation .tl_set:N = \l_guide_second_affil_tl,
secondauthor / email .tl_set:N = \l_guide_second_email_tl,
thirdauthor / firstname .tl_set:N = \l_guide_third_firstname_tl,
thirdauthor / lastname .tl_set:N = \l_guide_third_lastname_tl,
thirdauthor / affiliation .tl_set:N = \l_guide_third_affil_tl,
thirdauthor / email .tl_set:N = \l_guide_third_email_tl,
leftlogo .tl_set:N = \l_guide_leftlogo_tl,
rightlogo .tl_set:N = \l_guide_rightlogo_tl,
number .int_set:N = \l_guide_number_int,
title .tl_set:N = \l_guide_title_tl,
keywords .tl_set:N = \l_guide_keywords_tl,
url .tl_set:N = \l_guide_url_tl,
firstauthor .initial:n = { firstname = a, lastname = b,
affiliation = c, email = d},
secondauthor .initial:n = { firstname = g, lastname = h,
affiliation = i, email = j},
thirdauthor .initial:n = { firstname = g, lastname = h,
affiliation = i, email = j},
url .initial:n = {https://ku.edu},
number .initial:n = 42,
title .initial:n = {Guide ~ to ~ Guides},
keywords .initial:n = {guide},
}
\NewDocumentCommand \guidehdr { +o }
{
\group_begin:
\IfValueT { #1 }
{
\bool_set_false:N \l_guide_twoauthors_bool
\keys_set:nn { guide } { #1 }
}
\guide_hdr:
\group_end:
}
\cs_new_protected:Nn \guide_hdr:
{
\noindent
\begin{tabularx}{\textwidth}{|>{\centering\arraybackslash}p{1.25in}>{\centering\arraybackslash}X>{\raggedleft\arraybackslash}p{1.25in}|}
\hline
\begin{minipage}[c]{\linewidth}
\begin{center}
\includegraphics[width=\linewidth]{\l_guide_leftlogo_tl}
\par
\bigskip
{\small{}\textbf{Guide ~ No}: ~ \int_to_arabic:n { \l_guide_number_int }}
\end{center}%
\end{minipage} &
\begin{minipage}[c][1\totalheight][b]{3.5in}%
\bigskip
\begin{center}
\begin{minipage}[t][1\totalheight][b]{1\columnwidth}%
\begin{center}
\textbf{ \large \l_guide_title_tl }\\
\rule[0.5ex]{1\linewidth}{1pt}
\par\end{center}%
\end{minipage}
\par
\end{center}
\begin{minipage}[t]{1\columnwidth}
\begin{center}
\textbf{\l_guide_first_firstname_tl {} ~ \l_guide_first_lastname_tl}, ~\l_guide_first_affil_tl {} ~ <\href{mailto:\l_guide_first_email_tl}{\l_guide_first_email_tl} >
\bool_if:NT \l_guide_twoauthors_bool
{
\\
\textbf{\l_guide_second_firstname_tl {} ~ \l_guide_second_lastname_tl}, ~\l_guide_second_affil_tl {} ~ <\href{mailto:\l_guide_second_email_tl}{\l_guide_second_email_tl} >
}
\bool_if:NT \l_guide_threeauthors_bool
{
\\
\textbf{\l_guide_third_firstname_tl {} ~ \l_guide_third_lastname_tl}, ~\l_guide_third_affil_tl {} ~ <\href{mailto:\l_guide_third_email_tl}{\l_guide_third_email_tl} >
}
\par
\end{center}
\end{minipage}
\smallskip
\par
\begin{flushleft}
\medskip
\textbf{Keywords}: ~ \l_guide_keywords_tl \\
See ~ \url{\l_guide_url_tl} ~ for ~ updates.
\par
\end{flushleft}
\smallskip
\end{minipage} &
\begin{minipage}[c]{\linewidth}
\begin{center}
\includegraphics[width=\linewidth]{\l_guide_rightlogo_tl}
\par
\bigskip
\crmda\today
\end{center}%
\end{minipage}
\tabularnewline
\hline
\end{tabularx}
}
\ExplSyntaxOff
%%END This ends the custom header
\begin{document}
%% Fill in values of the arguments here,
%% If blanks are needed, must insert value " ~ "
%% If comma needed inside value, wrap in {}.
%% Delete secondauthor and thirdauthor if not needed
\guidesetup{%
firstauthor={
lastname=Author,
firstname=First,
affiliation=Title{,}~Institute,
[email protected]},
secondauthor={
lastname=Author,
firstname=Second,
affiliation=Title{,}~Institute,
[email protected]},
thirdauthor={
lastname=Author,
firstname=Third,
affiliation=Title{,}~Institute,
[email protected]},
url={https://your.website.here.edu/guides},
keywords={knitr, LaTeX, reproducible documents},
title={A Title for Skeleton Template: rnw2pdf-guide-knit},
leftlogo={theme/logoleft.pdf},
rightlogo={theme/logo-vert.pdf},
number=-1
}
\guidehdr
HOWDY!
\end{document}
\prop
list)\prop
list feature of expl3 --- you could easily store the various authors to a prop list and then check with\prop_if_in:NnTF \my_prop_list {firstauthor} { Do this}{ Do that}
etc, with secondauthor etc. as well instead of defining a new\bool
macro for each