Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring and recalling variable number of text strings in LaTeX
    primarykey
    data
    text
    <p>I'm currently writing an API document in LaTeX. I have a tabular environment with a list of error codes and descriptions, like so:</p> <pre><code>\begin{tabular}{|c|l|} \hline \textbf{Code} &amp; \textbf{Description} \\ \hline 1 &amp; (description of error 1) \\ \hline 2 &amp; (description of error 2) \\ \hline \end{tabular} </code></pre> <p>At various places later in the document, I reference an error's code and its description together, like so:</p> <pre><code>Possible error conditions: \begin{itemize} \item 1---(description of error 1) \end{itemize} </code></pre> <p>I want to automate this process so I don't have to retype the descriptions every time. I have tried using a counter, labels, and the \savebox command, but it's pretty cumbersome:</p> <pre><code>\newcounter{error} % Inside the tabular environment: \newsavebox{\ErrorOne} \savebox{\ErrorOne}{(description of error 1)} \refstepcounter{error} \label{ErrorOne} \arabic{error} &amp; \usebox{\ErrorOne} \\ \hline </code></pre> <p>and later, to reference the error,</p> <pre><code>\ref{ErrorOne}---\usebox{\ErrorOne} </code></pre> <p>I particularly object to having to use ErrorOne for the labels but \ErrorOne (with the leading backslash) for the saveboxes. I also don't really want names like ErrorOne, since I might need to change the order at some point. What I want is to be able to define a few commands:</p> <pre><code>\newerror{errorlabel}{Description} % defines the error (doesn't output anything) \errorcode{errorlabel} % outputs the error code \errordesc{errorlabel} % outputs the error description </code></pre> <p>and then be able to say something like</p> <pre><code>\newerror{ArgumentError}{Too many arguments} \newerror{DatabaseError}{Could not connect to database} % Inside the tabular environment: \errorcode{ArgumentError} &amp; \errordesc{ArgumentError} \\ \hline \errorcode{DatabaseError} &amp; \errordesc{DatabaseError} \\ \hline % Later on: \errorcode{DatabaseError}---\errordesc{DatabaseError} </code></pre> <p>with the error codes (1, 2, 3, ...) being automatically generated like labels would be.</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload