LaTeX: creating and using variables to save time and reduce typing errors

Variables and legal documents

My work consists of writing legal documents.

Legal documents are full of data and many of them have to be repeatedly inserted.

Think, for example, about the names of people or of places, dates of events, etc.

A method is needed to avoid manually repeating recurring data when writing documents, both to avoid wasting time and typing errors.

A good system is to use “variables”, i.e. placeholders that take on different values depending on the documents in which they are inserted.

Almost every digital writing system has its own management of “variables”.

LaTeX and variables

I use LaTeX to write my legal documents.

In my humble opinion, it’s the best system for the production of technical, scientific and also legal documents!

The management of variables in LaTeX is closely related to the management of commands.

As you can create “ new commands “ to expand the system, you can use the same method to create text variables that you can insert anywhere in your documents.

So, the solution is to use the newcommand command to create any variables you need.

Using “newcommand” to creare your own variables

It’s really easy to create a variable with newcommand, it is enough to respect the following syntax:

\newcommand{\variablename}{content_of_variable}

In the above string you can see three parts:

  1. the first part shows the backslash and the command to create other commands: \newcommand
  2. the second part shows the creation of the variable that, as every LaTeX command, needs the backslash before it: \variablename
  3. in the the third part content is assigned to the variable. Here you can insert text or numbers that will be printed in place of the variable.

The string must be inserted in the preamble of the LaTeX document.

You can now write the \variablename as a placeholder everywhere among the begin/end{document} tags and LaTeX will automatically replace the variable name with its effective value during compilation.

If you need to get a white space after the word in the compiled document you must add another backslash character at the end of the placeholder: then the string \variablename becames \variablename\.

But if the placeholder ends with a dot or other punctuation marks, you must not add the backslash ad the end of it.

Thak You for Your attention.

Originally published at https://francopasut.netlify.app on September 15, 2021.

--

--

--

I am a lawyer and occasionally write about technology.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Franco Pasut

Franco Pasut

I am a lawyer and occasionally write about technology.

More from Medium

If…Else Statements | C#

Regex Matching URL

Create your own plugin in Nvim with Python.