# Define reusable content --- preferably in the body or else in the header

I am writing a document where name of a person A will appear at multiple places section A. Similarly, name of person B will appear at multiple places in section B, etc.

Is there any way by which just before section A, I can define a variable, say, PersonName, assign a value relevant to Person A to it, and use it in section A. Then, redefine PersonName at the beginnig of section B, use it in section B, etc.

If PersonName can not be defined in the body, can I declare it in the preamble and keep assigning different values to it in the body?



\documentclass{article}
\begin{document}
\section{Section A}
\newcommand{\PersonName}{Person A}
Some text written by \PersonName.

\section{Section B}
\renewcommand{\PersonName}{Person B}
Some text written by \PersonName.
\end{document}

• Is there an equivalent of \newcommand in the document body? So that it's just local, like how you might use {\bf yada yada}?
– Jeff
Nov 25, 2018 at 20:26
• This should be a separate question, but has probably been answered here: tex.stackexchange.com/questions/105684/… Nov 27, 2018 at 13:53

With the 'scontents' package it's easy enough to do what you're looking for. All stored in memory, of course, if you prefer external files, you can use environment version an the key write-env=file.tex and besides storing them in memory, you can have the content in separate files and then use \input. I prefer to save in memory :)

\documentclass{article}
\usepackage{scontents}
\setupsc{store-cmd=person}
\Scontents{Person A}
\Scontents{Person B}
\begin{document}
\section{Section A}
Some text written by \getstored[1]{person}

\section{Section B}
Some text written by \getstored[2]{person}
\end{document}