0

I am currently using the memoir package to write the rules document for a live roleplaying system. As part of this, I need to include technical information - "Calls" - which are verbal instructions to behave in a particular way. I'd like these to appear in the text in a certain way, with contextual information around them - but I'd also like to be able to reproduce them in an appendix chapter, sort of like a glossary or list of keywords or library functions, with single-sourcing somehow so that I only have to write out the text of calls once.

\documentclass{article}
\begin{document}
\begin{center}
\fbox{
  \begin{minipage}{0.9\textwidth}
  \begin{tabular}{p{0.1\textwidth} p{0.8\textwidth}}
    \textsc{Stun} & Remain immobile for five seconds.
  \end{tabular}
\end{minipage}}
\end{center}
\end{document}

This is a MWE for what I want a call to look like inline, though I'm not wedded to this particular representation - it's just a mockup. I'm wanting the easiest, slickest way of doing this kind of thing - clearly it's not too much work to hack it but I'd love to be able to automate this. I know that there's a package for restating theorems but that seems a little far from the context of what I want to do.

0

2 Answers 2

1

Simple starting point for LuaLaTeX:

\documentclass{article}
% define calls and their descriptions here
\directlua{calls = {
  ["stun"] = "Remain immobile for five seconds.",
  ["smile"] = "Smile for five seconds."
}}

\newcommand{\calldesc}[1]{\directlua{tex.sprint(calls["#1"])}}

\begin{document}
\begin{center}
\fbox{
  \begin{minipage}{0.9\textwidth}
  \begin{tabular}{p{0.1\textwidth} p{0.8\textwidth}}
    \textsc{stun} & \calldesc{stun}
  \end{tabular}
  \end{minipage}}
\end{center}

\section*{List of Calls}
\begin{tabular}{|l|l|}
\hline
Call & Description \\
\hline
\directlua{
output = {}
for name, desc in pairs(calls) do
  table.insert(output, name .. " & " .. desc .. " \\\\")
end
tex.print(output)
}
\hline
\end{tabular}
\end{document}

enter image description here

0

If you need a lookup-table, you can maintain that via a database of the package datatool.

The lookup can be done via dadatool's \DTLfetch.

Printing the list/table can be done via \DTLforeach or via \DTLdisplaylongdb or via \DTLdisplaydb.

\documentclass{memoir}
\usepackage{datatool,longtable, etoolbox}

\makeatletter
% datatool seems to have a bug, see <https://tex.stackexchange.com/q/642775/118714>,
% so let's fix it:
\expandafter\patchcmd\expandafter{\csname\string\DTLdisplaylongdb\endcsname}%
         {\@dtl@resetdoamp\dtldisplaystarttab}%
         {\dtldisplaystarttab\@dtl@resetdoamp}%
         {\message{Patching succeeded.}}%
         {\message{Patching failed.}}%
\makeatother

%===============================================================================
\DTLnewdb{calls}
\DTLaddcolumn{calls}{WhatKindOfCall}
\DTLsetheader{calls}{WhatKindOfCall}{Call}
\DTLaddcolumn{calls}{DescriptionOfCall}
\DTLsetheader{calls}{DescriptionOfCall}{Description}
%-------------------------------------------------------------------------------
\DTLnewrow{calls}
\DTLnewdbentry{calls}{WhatKindOfCall}{Stun}
\DTLnewdbentry{calls}{DescriptionOfCall}{Remain immobile for five seconds}
%-------------------------------------------------------------------------------
\DTLnewrow{calls}
\DTLnewdbentry{calls}{WhatKindOfCall}{Smile}
\DTLnewdbentry{calls}{DescriptionOfCall}{Smile for five seconds}
%-------------------------------------------------------------------------------
% This is one where you can use the optional argument of `\call` for
% passing in argument(s) to the macro which delivers the description.
\DTLnewrow{calls}
\DTLnewdbentry{calls}{WhatKindOfCall}{OptArg}
\newcommand\OptArg[1][\textit{\textlangle X\textrangle}]{Do this for #1 minutes}
\DTLnewdbentry{calls}{DescriptionOfCall}{\OptArg}
%===============================================================================


\newcommand\call[2][]{%
  \begin{center}%
  \begin{tabular}{|p{0.1\textwidth}p{0.8\textwidth}|}%
  \hline
  \textsc{\DTLfetch{calls}{WhatKindOfCall}{#2}{WhatKindOfCall}}&%
  \DTLfetch{calls}{WhatKindOfCall}{#2}{DescriptionOfCall}#1\\%
  \hline
  \end{tabular}%
  \end{center}%
}%

\begin{document}

\section*{List of kinds of calls}
\begingroup
\renewcommand{\dtldisplaystarttab}{\hline}%
\renewcommand\dtldisplayafterhead{\hline}%
\renewcommand\dtldisplaystartrow{\hline}%
\renewcommand{\dtldisplayendtab}{\tabularnewline\hline}%
\renewcommand{\dtlbeforecols}{|}%
\renewcommand{\dtlaftercols}{|}%
\renewcommand{\dtlbetweencols}{|}%
\renewcommand\dtlheaderformat[1]{\textbf{#1}\hfil\null}%
\DTLdisplaylongdb{calls}
\endgroup

\bigskip
\hrule
\bigskip

some text

\call{Stun}

some text

\call{Smile}

some text

\call{OptArg}

some text

\call[{[{3}]}]{OptArg}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .