storage - Storing and recalling variable number of text strings in LaTeX -
I am currently writing an API document in latex. I have a tabular environment with a list of error codes and details such as:
\ begin {tabular} {| C | L |} \ hline \ textbf {code} & amp; \ Textbf {Details} \\ \ hline 1 & amp; (Details of error 1) \\ \ hline 2 & amp; (Details of Error 2) \\ \ hline \ end {tabular}
Later on in different documents in the document, I refer to an error code and its details at the same time, such as:
Possible error status: \ start {itemize} \ item 1 --- (error description 1) \ end {itemize}
I I want to automate the process so I do not have to type the details again every time I try to use a counter, labels, and \ savebox command , But it is very complex:
\ newcounter {error}% in tabular environment: \ newsavebox {\ ErrorOne} \ savebox {\ ErrorOne} {(description of 1 error)} \ Refstepcounter {error} \ label {errorOn} \ Arabic {error} & amp; \ Usebox {\ ErrorOne} \\ \ hline
and later, to reference the error,
\ {errorOne} --- \ Objectbox {\ ErrorOne}
I have an object specifically for using ErrorOne for labels, but for \ Saveboxes \ ErrorOne (with leading backslash). I do not really want a name like error on, because I might have to change the order at some point. All I have to do should be able to define some command:
\ newerror {errorlabel} {description}% defines error (no one does not output) \ errorcode {Errorlabel}% outputs the error code \ errordesc {errorlabel}% error description
and then
\ newerror {ArgumentError} {lots All logic} \ Newerror {DatabaseError} {could not connect to the database}% Tabular inside the environment: \ errorcode {ArgumentError} & amp; \ Errordesc {ArgumentError} \\ \ hline \ errorcode {DatabaseError} & amp; \ Errordesc {DatabaseError} \\ \ hline% at: \ errorcode {DatabaseError} --- \ errordesc {DatabaseError}
Error code (1, 2, 3, .... )
Any thoughts?
does the following for me
\ catcode` \ @ 11 = Newcomer {error} \ def \ newerror # 1 # 2 {\ refstepcounter {error}% \ expandafter \ xdef \ csname errno @ # 1 \ endcsname {\ arabic {error}}% \ expandafter \ xdef \ csname errds @ # 1 \ endcsname {# 2}%} \ def \ errorcode # 1 {\ expandafter \ printerrinfo \ csname errno @ # 1 \ endcsname} \ Def \ errordesc # 1 {\ expandafter \ printerrinfo \ csname errds @ # 1 \ endcsname} \ Def \ printerrinfo # 1 {\ ifx # 1 \ relax \ errmessage {error code is invalid}% \ and \ extended # 1 \ fi} \ Catcode \ \ @ 12 = newerror {ArgumentError} {lots of arguments} \ new terror {DatabaseError} {Could not connect to database} \ Errorcode {DatabaseError} --- \ erordesc {DatabaseError}
Comments
Post a Comment