Skip to content

Autofilling Values

jc-cisneros edited this page Oct 2, 2023 · 5 revisions

Hard-coded values

To facilitate reproducibility, figures and tables should always be generated programmatically and never include hard-coded values. The tablefill package of gslab_make is a useful tool to help create complex tables.

In-text values (scalars)

Frequently, it is necessary to include values derived from calculations in the text of a document. For example, we may wish to reference a coefficient from a regression specification. To facilitate reproducibility and avoid text from becoming outdated, it is recommended to include values programatically. Below, we detail methods for doing so.

Creating scalars

Using a program of your choice (e.g., R), generate the file scalars.tex containing the scalars formatted as new TeX command, as illustrated below. The new command should be named after the scalar (e.g. scalarnamemath and scalarnametext). The command should output the scalar value. Note that LaTeX places restrictions on how new commands may be named.

\newcommand{scalarnamemath}{value} % this command displays your scalar value in math mode
\newcommand{scalarnametext}{\textnormal{value}} % this command displays your scalar value as normal text

If you are using R, you can use the AutoFill function from gslab_r to export scalars. For sample code on how to pre-format scalars and use the AutoFill function, access here.

Adding scalars to LyX

  1. Go to Document, Settings, and then LaTeX Preamble. Paste in the following. Here, scalars refers to a scalars.tex file located in the same directory as the LyX document. You may rename scalars according to your preferences. For example, \input{../more_scalars} would refer to a more_scalars.tex file located in the parent directory of the LyX document. To create a scalars.tex file, see Creating scalars.
\input{scalars}
  1. Use the command \scalarnamemath to display the value in math mode. Use the command \scalarnametext to display the value in text mode.

Adding scalars to LaTeX

  1. In the document preamble, paste in the following. Here, scalars refers to a scalars.tex file located in the same directory as the LaTeX document. You may rename scalars according to your preferences. For example, \input{../more_scalars} would refer to a more_scalars.tex file located in the parent directory of the LaTeX document. To create a scalars.tex file, see Creating scalars.
\input{scalars}
  1. Use the command \scalarnamemath to display the value in math mode. Use the command \scalarnametext to display the value in text mode.

Comments

In cases where including a hard-coded value in-text is unavoidable, include a red LaTeX comment for fact-checking. Yellow LyX comments should be used for comments between coauthors to be resolved and deleted.