Guest User

The simple method

a guest
Dec 4th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 1.46 KB | None | 0 0
  1. \documentclass{article}
  2.  
  3. \usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
  4. \usepackage{etoolbox}    %% <- for \csuse, \csdef, \ifcsdef and \forcsvlist
  5.  
  6. %% Define/retrieve a new keyword:
  7. \newcommand\setkeyword[3]{%
  8.   \csdef{keyw@descr@#1}{#2}%
  9.   \csdef{keyw@value@#1}{#3}%
  10. }
  11. \newcommand*\getkeyword[2]{%
  12.   \ifcsdef{keyw@#2@#1}{%         %% <- if the key is defined...
  13.     \csuse{keyw@#2@#1}%          %% <- return the description
  14.   }{%                            %% <- otherwise...
  15.     ??%                          %% <- let's just print ??
  16.   }%
  17. }
  18. \newcommand*\getdescription[1]{\getkeyword{#1}{descr}}
  19. \newcommand*\getvalue[1]{\getkeyword{#1}{value}}
  20.  
  21. %% Display a table describing a list of keywords:
  22. \newcommand*\keywordtable[1]{%
  23.   \begin{center}
  24.    \begin{tabular}{lrl}
  25.       \textbf{Parameter} & \textbf{Value} & \textbf{Description} \\
  26.      \forcsvlist{\tableentry}{#1} %% <- apply \tableentry to each value in #1
  27.     \end{tabular}
  28.  \end{center}%
  29. }
  30. \newcommand*\tableentry[1]{%
  31.     \formattableentry{\detokenize{#1}}{\getvalue{#1}}{\getdescription{#1}}%
  32. }
  33. \newcommand\formattableentry[3]{ #1 & #2 & #3 \\ }
  34.  
  35. % %% Declaration of keywords:
  36. \setkeyword{runtype}{A parameter}{1}
  37. \setkeyword{param_1}{Another parameter}{0}
  38. \setkeyword{param_2}{A third parameter}{42}
  39.  
  40. \begin{document}
  41.  
  42. \section{Runtype 1 description}
  43. \keywordtable{runtype,param_1}
  44.  
  45. \section{Runtype 2 description}
  46. \keywordtable{runtype,param_2}
  47.  
  48. \end{document}
Add Comment
Please, Sign In to add comment