0

I am writing a college course outline. It contains both a table with an overview of the dates and topics and a more extended outline of the specific topics later in the text. Ideally, I would like to input the dates into the table and have other places in the text echo the dates, so I don't have to make the changes in multiple places. I'm sure this is possible, I just don't know how.

  • 3
    If you say \def\dateColumbus{1492}, then wherever in the document you use \dateColumbus{}, the text 1492 will appear. – Steven B. Segletes Sep 16 '16 at 9:50
1

Using xparse, you could do something like this. Note that this uses the new and experimental(but stable) syntax from the LaTeX3-team. It is meant for class- and package-developers, so it follows a very different syntax than LaTeX and TeX. The same code could ofcourse be made in TeX also.

Here, you get info by writing \vars{name}, where name would produce your name.

You could of course use just a regular \newcommand{\myname}{John Doe} and you would have a variable by calling \myname. It depends on what kind of syntax you want.

Output

enter image description here

Code

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\vars}{m}
 {
    \str_case_x:nn {\str_foldcase:n {#1}}
     {
      {name}{John\ Doe}
      {phone}{555\,12345}
      {mytable}{%
        \begin{tabular}{lr}
          \hline
          Foo & Bar \\
          \hline
          \vars{name} & \vars{phone}\\
          \hline
        \end{tabular}
        }
     }
 }
\ExplSyntaxOff

\begin{document}

My name is \vars{name}.

\begin{table}[hbt]
  \centering
  \caption{My info}
  \vars{mytable}
\end{table}


\end{document}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.