GeneralMultiple instructions where only some data differs

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Macki
Posts: 2
Joined: Thu Dec 30, 2021 11:33 pm

Multiple instructions where only some data differs

Post by Macki »

Hi all.

I'm completely new on LaTeX and picked it up to try to solve a task.
I'm about to write multiple instructions for some articles. The instructions will almost be identical with only some numbers, names and sentences that differs between them.
I've tried to read about LaTeX to find out if it can solve that problem. It looks like it if you look at how it handles bibliographies but I haven't found any good examples how to do it.

I would imagine it would be is something like this:
This is a text about {file.brand} and it is {file.length} long.

And then there is another file where I declare all the variables like it does in the bib file.

I don't know if I make any sense, but if any of you could point me in the right direction it would be awesome.

Thanks a lot
Macki

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Multiple instructions where only some data differs

Post by Ijon Tichy »

TeX is a macro language. So in LaTeX you would usually define commands somewhere and use them, e.g.,

Code: Select all

% Note: The file test-template.tex can be a stand alone file.
%       I generate it here from the data file via filecontents
%       only to make it work in the online compiler.
\begin{filecontents}[force]{test-template.tex}
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\NAME{} is a \GENDER{}, who sometimes can be found on \PLACE{}.
\end{document}
\end{filecontents}

\newcommand*{\NAME}{Ijon Tichy}
\newcommand*{\GENDER}{man}
\newcommand*{\PLACE}{\url{https://LaTeX.org}}
\input{test-template.tex}
\endinput
You can make many files with other data but using the same template file, e.g.:

Code: Select all

% Note: This example will not work in the online compiler,
%       because it needs test-template.tex from the
%       previous example.
\newcommand*{\NAME}{Stefan}
\newcommand*{\GENDER}{man}
\newcommand*{\PLACE}{several \LaTeX{} sites}
\input{test-template.tex}
Please read an introduction to LaTeX for more information about \newcommand, \input and all the other commands and environments used in the example.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Macki
Posts: 2
Joined: Thu Dec 30, 2021 11:33 pm

Multiple instructions where only some data differs

Post by Macki »

Awesome!

Thank you so much for the answer.
Post Reply