How to repeat the same content in different tables?












3















I have a list of keywords and descriptions for those keywords. I would like to have tables for the different contexts in which these are used, containing only the relevant ones for the case. Some of these keywords repeat on the different contexts, so it would be ideal to write the description only once and then "reference" that description in each of my tables for ease of maintenance.



Example:



section{Runtype 1 description}
begin{table}
begin{center}
begin{tabular}{ l l }
runtype & Keyword to determine runtype. Can be 1 or 2. \
& I don't want to hardcode this description twice...\
param_1 & Keyword to determine the parameter of runtype = 1 \
end{tabular}
end{center}
end{table}

section{Runtype 2 description}
begin{table}
begin{center}
begin{tabular}{ l l }
runtype & Keyword to determine runtype. Can be 1 or 2. \
& I don't want to hardcode this description twice...\
param_2 & Keyword to determine the parameter of runtype = 2 \
end{tabular}
end{center}
end{table}









share|improve this question


















  • 3





    Welcome to TeX.SE!

    – Kurt
    Nov 27 '18 at 21:11
















3















I have a list of keywords and descriptions for those keywords. I would like to have tables for the different contexts in which these are used, containing only the relevant ones for the case. Some of these keywords repeat on the different contexts, so it would be ideal to write the description only once and then "reference" that description in each of my tables for ease of maintenance.



Example:



section{Runtype 1 description}
begin{table}
begin{center}
begin{tabular}{ l l }
runtype & Keyword to determine runtype. Can be 1 or 2. \
& I don't want to hardcode this description twice...\
param_1 & Keyword to determine the parameter of runtype = 1 \
end{tabular}
end{center}
end{table}

section{Runtype 2 description}
begin{table}
begin{center}
begin{tabular}{ l l }
runtype & Keyword to determine runtype. Can be 1 or 2. \
& I don't want to hardcode this description twice...\
param_2 & Keyword to determine the parameter of runtype = 2 \
end{tabular}
end{center}
end{table}









share|improve this question


















  • 3





    Welcome to TeX.SE!

    – Kurt
    Nov 27 '18 at 21:11














3












3








3








I have a list of keywords and descriptions for those keywords. I would like to have tables for the different contexts in which these are used, containing only the relevant ones for the case. Some of these keywords repeat on the different contexts, so it would be ideal to write the description only once and then "reference" that description in each of my tables for ease of maintenance.



Example:



section{Runtype 1 description}
begin{table}
begin{center}
begin{tabular}{ l l }
runtype & Keyword to determine runtype. Can be 1 or 2. \
& I don't want to hardcode this description twice...\
param_1 & Keyword to determine the parameter of runtype = 1 \
end{tabular}
end{center}
end{table}

section{Runtype 2 description}
begin{table}
begin{center}
begin{tabular}{ l l }
runtype & Keyword to determine runtype. Can be 1 or 2. \
& I don't want to hardcode this description twice...\
param_2 & Keyword to determine the parameter of runtype = 2 \
end{tabular}
end{center}
end{table}









share|improve this question














I have a list of keywords and descriptions for those keywords. I would like to have tables for the different contexts in which these are used, containing only the relevant ones for the case. Some of these keywords repeat on the different contexts, so it would be ideal to write the description only once and then "reference" that description in each of my tables for ease of maintenance.



Example:



section{Runtype 1 description}
begin{table}
begin{center}
begin{tabular}{ l l }
runtype & Keyword to determine runtype. Can be 1 or 2. \
& I don't want to hardcode this description twice...\
param_1 & Keyword to determine the parameter of runtype = 1 \
end{tabular}
end{center}
end{table}

section{Runtype 2 description}
begin{table}
begin{center}
begin{tabular}{ l l }
runtype & Keyword to determine runtype. Can be 1 or 2. \
& I don't want to hardcode this description twice...\
param_2 & Keyword to determine the parameter of runtype = 2 \
end{tabular}
end{center}
end{table}






tables






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '18 at 21:06









NordicoNordico

1183




1183








  • 3





    Welcome to TeX.SE!

    – Kurt
    Nov 27 '18 at 21:11














  • 3





    Welcome to TeX.SE!

    – Kurt
    Nov 27 '18 at 21:11








3




3





Welcome to TeX.SE!

– Kurt
Nov 27 '18 at 21:11





Welcome to TeX.SE!

– Kurt
Nov 27 '18 at 21:11










3 Answers
3






active

oldest

votes


















3














Below, I'm defining the following commands:





  • setkeyword{<keyword>}{<description>} can be used to declare a keyword.


  • getkeyword{<keyword>} retrieves the description you provided.


  • keywordtable{<key1>,<key2>,…} displays a table containing the descriptions corresponding to a comma-separated list of keywords.


(Note that keywords containing underscores are allowed.)



documentclass{article}

usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
usepackage{etoolbox} %% <- for csuse, csdef, ifcsdef and forcsvlist

%% Define/retrieve a new keyword:
newcommandsetkeyword[2]{csdef{keyw@#1}{#2}}
newcommand*getkeyword[1]{%
ifcsdef{keyw@#1}{% %% <- if the key is defined...
csuse{keyw@#1}% %% <- return the description
}{% %% <- otherwise...
??% %% <- question marks
%errmessage{Undefined key: #1}% %% <- or an ERROR, if you prefer
}%
}

%% Display a table describing a list of keywords:
newcommand*keywordtable[1]{%
begin{tabular}{lp{8cm}}
forcsvlist{tableentry}{#1} %% <- apply tableentry to each value in #1
end{tabular}%
}
newcommand*tableentry[1]{%
formattableentry{detokenize{#1}}{getkeyword{#1}}%
}
newcommandformattableentry[2]{ #1 & #2 \ }

% %% Declaration of keywords:
setkeyword{runtype}{Keyword to determine runtype. Can be 1 or 2. par
I don't want to hardcode this description twiceldots}
setkeyword{param_1}{Keyword to determine the parameter of runtype = 1}
setkeyword{param_2}{Keyword to determine the parameter of runtype = 2}

begin{document}

section{Runtype 1 description}
keywordtable{runtype,param_1}

section{Runtype 2 description}
keywordtable{runtype,param_2}

end{document}


output





Some remarks





  • setkeyword{<keyword>}{<description>} effectively defines keyw@<keyword> for you, so that it expands to <definition>. You can't use this macro directly because its name contains an @.


  • getkeyword{<keyword>} just calls keyw@<keyword>.

  • I'm using the e-TeX primitive detokenize to print the keyword. This command strips all tokens in its argument of their special meaning (by changing their catcodes), so you can for instance use detokenize{param_1} safely.

  • Without usepackage[T1]{fontenc}, underscores are displayed as " ̇", rather than as "_". You'll probably want to use this package anyway because of the reasons outlined here.

  • I'm using tabularx to create a table that has the same width as the current line width. You can replace linewidth by some other value if you want a different width (or just use tabular, in which case you should replace the X column type by something else).






A more customisable version



By request, here is the most customisable version I can think of. This lets you create keywords using setkeyword{<keyword>}{<key1>=<value1>,<key2>=<value2>,…} and retrieve them using getkeyword{<keyword>}{<key>}.
You can create a table with rows corresponding a set of keywords and columns corresponding to specific keys using



keywordtable[<key1>,<key2>,…]{<keyword1>,<keyword2>,…}


I'm using pkgkeys, which is documented in section 82 of the pgf manual.



documentclass{article}

usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
usepackage{pgfkeys} %% <- for everything starting with pgf
usepackage{etoolbox} %% <- for forcsvlist

newcommand*{declarekeyword}[1]{%
pgfkeys{
/keyw/#1/.is family,
/keyw/#1/.unknown/.style = {pgfkeyscurrentpath/pgfkeyscurrentname/.initial={##1}},
}%
}
newcommandsetkeyword[2]{%
declarekeyword{#1}%
pgfkeys{/keyw/#1/.cd,name=detokenize{#1},#2}%
}
newcommand*getkeyword[2]{pgfkeysvalueof{/keyw/#1/#2}}

%% Display a table describing a list of keywords:
newcommand*keywordtable[2][name,description]{%
begin{center}
begin{tabular}{forcsvlist{getkeyword{@alignment}}{#1}}
forcsvlist{tableentry[bfseries]{#1}}{@headings}
forcsvlist{tableentry{#1}}{#2}
end{tabular}
end{center}%
}
newcommand*tableentry[3]{%
letkeywcolsepempty
forcsvlist{keywcolsepdefkeywcolsep{&}formattableentry[#1]{#3}}{#2}\
}
newcommand*formattableentry[3]{#1{getkeyword{#2}{#3}}}

%% "Fake" keywords (control column titles and alignment)
setkeyword{@headings}{name=Parameter,description=Description,value=Value}
setkeyword{@alignment}{name=l,description=l,value=r}

%% Declaration of keywords:
setkeyword{runtype}{description=A parameter,value=1}
setkeyword{param_1}{description=Another parameter,value=0}
setkeyword{param_2}{name=detokenize{PARAM_2},description=A third parameter,value=42}

begin{document}

section{Runtype 1 description}
keywordtable{runtype,param_1}

section{Runtype 2 description}
keywordtable[name,value,description]{runtype,param_2}

end{document}


output






share|improve this answer


























  • Awesome! This is a very versatile method and thorough response, thank you very much! It is a bit complex and wordy (at least in setup) for something that feels conceptually simple, but apparently that's just how latex is. Not sure what's the difference between tabular and tabularx, but the later didn't compile correctly for me so went back to the former.

    – Nordico
    Nov 29 '18 at 2:27






  • 1





    @Nordico begin{tabularx}{linewidth}{lX} creates a table of total width linewidth whose second column stretches to accommodate. It was very much inessential to the answer, so I probably shouldn't have used it. (I needed to use either the p{<some width>} or the X column type because one of the entries spans two lines.)

    – Circumscribe
    Nov 29 '18 at 9:04








  • 1





    It is 1-1, but you could for instance have setkeyword call csdef twice to make it 1-2, like I've done here. I can think of a few other (fancier) ways to do this, but those wouldn't really perform any better than this.

    – Circumscribe
    Dec 4 '18 at 21:45






  • 1





    @Nordico See the bottom part of my answer for a ridiculously customisable version.

    – Circumscribe
    Dec 5 '18 at 9:17






  • 1





    @Nordico You can use description={something containing = and ,.}. This actually didn't work because I had forgotten to wrap the ##1 in the /keyw/#1/.unknown/.style = … line by {}. (Fixed now)

    – Circumscribe
    Dec 5 '18 at 18:58



















2














documentclass[12pt]{article}
newcommandzzz{%
runtype & Keyword to determine runtype. Can be 1 or 2. \
& I don't want to hardcode this description twice...}
begin{document}
section{Runtype 1 description}
begin{table}[ht]
begin{center}
begin{tabular}{ l l }
zzz\
param_1 & Keyword to determine the parameter of runtype = 1 \
end{tabular}
end{center}
end{table}

section{Runtype 2 description}
begin{table}[ht]
begin{center}
begin{tabular}{ l l }
zzz\
param_2 & Keyword to determine the parameter of runtype = 2 \
end{tabular}
end{center}
end{table}
end{document}


enter image description here






share|improve this answer
























  • Ok, this works but feels like using a cannon to kill a fly. More precisely: I need to use this with around a hundred keywords, is defining a hundred newcommand to use as a "reference dictionary" advisable? How can I use descriptive names (tablekey_keyname) without using underscores?

    – Nordico
    Nov 27 '18 at 21:20











  • @Nordico As to how to use underscores in a command name, options are limited: 1) change catcode of _ (not recommended, as it breaks subscript math), or 2) csdef and csuse with the etoolbox package (recommended if you insist on underscore in name)

    – Steven B. Segletes
    Nov 27 '18 at 21:24













  • I mean, not necessarily an underscore, it can be other symbol ("tablekey.keyname") or a way of structuring the commands (like an equivalent to C++ namespaces, so I could do "tablekey::keyname"), anything that makes it more human readable/usable than just altogether "tablekeykeyname".

    – Nordico
    Nov 27 '18 at 21:29








  • 1





    @Nordico In my example, add catcode`:=11 as the first line after documentclass, This changes : to be a "letter". Then newcommandzz:z{...} can be defined and later used as zz:z. What I don't know is if this breaks anything (e.g., spacing, hyphenation), if you use : as a normal character.

    – Steven B. Segletes
    Nov 27 '18 at 21:36








  • 1





    I thought zzz was reserved for @David Carlisle ;-)

    – Raoul Kessels
    Nov 28 '18 at 11:12



















1














It depends on where you want to first key the description you want to repeat.



Probably the best place is in the document preamble or in an external file that you can input.



documentclass{article}
usepackage{xparse}

% a few line of code for setting up the system
ExplSyntaxOn

NewDocumentCommand{newdesc}{mm}
{% #1 is a key, #2 is the description
prop_gput:Nnn g_nordico_descriptions_plist { #1 } { #2 }
}

NewDocumentCommand{getdesc}{m}
{% #1 is a key
prop_if_in:NnTF g_nordico_descriptions_plist { #1 }
{ prop_item:Nn g_nordico_descriptions_plist { #1 } }
{ ???~non~existent~description~??? }
}

prop_new:N g_nordico_descriptions_plist

ExplSyntaxOff

% the descriptions (they can go in an external file
% say desc.tex and here you'd do input{desc}

newdesc{A}{I don't want to hardcode this description twice...}

begin{document}

section{Runtype 1 description}
begin{center}
begin{tabular}{ l l }
runtype & Keyword to determine runtype. Can be 1 or 2. \
& getdesc{A} \
param_1 & Keyword to determine the parameter of runtype = 1 \
end{tabular}
end{center}

section{Runtype 2 description}
begin{center}
begin{tabular}{ l l }
runtype & Keyword to determine runtype. Can be 1 or 2. \
& getdesc{A} \
param_2 & Keyword to determine the parameter of runtype = 2 \
end{tabular}
end{center}

end{document}


Note that it is not at all necessary to place a tabular in a floating table environment (which might make the tabular go to another page).



enter image description here






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "85"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f462072%2fhow-to-repeat-the-same-content-in-different-tables%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    Below, I'm defining the following commands:





    • setkeyword{<keyword>}{<description>} can be used to declare a keyword.


    • getkeyword{<keyword>} retrieves the description you provided.


    • keywordtable{<key1>,<key2>,…} displays a table containing the descriptions corresponding to a comma-separated list of keywords.


    (Note that keywords containing underscores are allowed.)



    documentclass{article}

    usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
    usepackage{etoolbox} %% <- for csuse, csdef, ifcsdef and forcsvlist

    %% Define/retrieve a new keyword:
    newcommandsetkeyword[2]{csdef{keyw@#1}{#2}}
    newcommand*getkeyword[1]{%
    ifcsdef{keyw@#1}{% %% <- if the key is defined...
    csuse{keyw@#1}% %% <- return the description
    }{% %% <- otherwise...
    ??% %% <- question marks
    %errmessage{Undefined key: #1}% %% <- or an ERROR, if you prefer
    }%
    }

    %% Display a table describing a list of keywords:
    newcommand*keywordtable[1]{%
    begin{tabular}{lp{8cm}}
    forcsvlist{tableentry}{#1} %% <- apply tableentry to each value in #1
    end{tabular}%
    }
    newcommand*tableentry[1]{%
    formattableentry{detokenize{#1}}{getkeyword{#1}}%
    }
    newcommandformattableentry[2]{ #1 & #2 \ }

    % %% Declaration of keywords:
    setkeyword{runtype}{Keyword to determine runtype. Can be 1 or 2. par
    I don't want to hardcode this description twiceldots}
    setkeyword{param_1}{Keyword to determine the parameter of runtype = 1}
    setkeyword{param_2}{Keyword to determine the parameter of runtype = 2}

    begin{document}

    section{Runtype 1 description}
    keywordtable{runtype,param_1}

    section{Runtype 2 description}
    keywordtable{runtype,param_2}

    end{document}


    output





    Some remarks





    • setkeyword{<keyword>}{<description>} effectively defines keyw@<keyword> for you, so that it expands to <definition>. You can't use this macro directly because its name contains an @.


    • getkeyword{<keyword>} just calls keyw@<keyword>.

    • I'm using the e-TeX primitive detokenize to print the keyword. This command strips all tokens in its argument of their special meaning (by changing their catcodes), so you can for instance use detokenize{param_1} safely.

    • Without usepackage[T1]{fontenc}, underscores are displayed as " ̇", rather than as "_". You'll probably want to use this package anyway because of the reasons outlined here.

    • I'm using tabularx to create a table that has the same width as the current line width. You can replace linewidth by some other value if you want a different width (or just use tabular, in which case you should replace the X column type by something else).






    A more customisable version



    By request, here is the most customisable version I can think of. This lets you create keywords using setkeyword{<keyword>}{<key1>=<value1>,<key2>=<value2>,…} and retrieve them using getkeyword{<keyword>}{<key>}.
    You can create a table with rows corresponding a set of keywords and columns corresponding to specific keys using



    keywordtable[<key1>,<key2>,…]{<keyword1>,<keyword2>,…}


    I'm using pkgkeys, which is documented in section 82 of the pgf manual.



    documentclass{article}

    usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
    usepackage{pgfkeys} %% <- for everything starting with pgf
    usepackage{etoolbox} %% <- for forcsvlist

    newcommand*{declarekeyword}[1]{%
    pgfkeys{
    /keyw/#1/.is family,
    /keyw/#1/.unknown/.style = {pgfkeyscurrentpath/pgfkeyscurrentname/.initial={##1}},
    }%
    }
    newcommandsetkeyword[2]{%
    declarekeyword{#1}%
    pgfkeys{/keyw/#1/.cd,name=detokenize{#1},#2}%
    }
    newcommand*getkeyword[2]{pgfkeysvalueof{/keyw/#1/#2}}

    %% Display a table describing a list of keywords:
    newcommand*keywordtable[2][name,description]{%
    begin{center}
    begin{tabular}{forcsvlist{getkeyword{@alignment}}{#1}}
    forcsvlist{tableentry[bfseries]{#1}}{@headings}
    forcsvlist{tableentry{#1}}{#2}
    end{tabular}
    end{center}%
    }
    newcommand*tableentry[3]{%
    letkeywcolsepempty
    forcsvlist{keywcolsepdefkeywcolsep{&}formattableentry[#1]{#3}}{#2}\
    }
    newcommand*formattableentry[3]{#1{getkeyword{#2}{#3}}}

    %% "Fake" keywords (control column titles and alignment)
    setkeyword{@headings}{name=Parameter,description=Description,value=Value}
    setkeyword{@alignment}{name=l,description=l,value=r}

    %% Declaration of keywords:
    setkeyword{runtype}{description=A parameter,value=1}
    setkeyword{param_1}{description=Another parameter,value=0}
    setkeyword{param_2}{name=detokenize{PARAM_2},description=A third parameter,value=42}

    begin{document}

    section{Runtype 1 description}
    keywordtable{runtype,param_1}

    section{Runtype 2 description}
    keywordtable[name,value,description]{runtype,param_2}

    end{document}


    output






    share|improve this answer


























    • Awesome! This is a very versatile method and thorough response, thank you very much! It is a bit complex and wordy (at least in setup) for something that feels conceptually simple, but apparently that's just how latex is. Not sure what's the difference between tabular and tabularx, but the later didn't compile correctly for me so went back to the former.

      – Nordico
      Nov 29 '18 at 2:27






    • 1





      @Nordico begin{tabularx}{linewidth}{lX} creates a table of total width linewidth whose second column stretches to accommodate. It was very much inessential to the answer, so I probably shouldn't have used it. (I needed to use either the p{<some width>} or the X column type because one of the entries spans two lines.)

      – Circumscribe
      Nov 29 '18 at 9:04








    • 1





      It is 1-1, but you could for instance have setkeyword call csdef twice to make it 1-2, like I've done here. I can think of a few other (fancier) ways to do this, but those wouldn't really perform any better than this.

      – Circumscribe
      Dec 4 '18 at 21:45






    • 1





      @Nordico See the bottom part of my answer for a ridiculously customisable version.

      – Circumscribe
      Dec 5 '18 at 9:17






    • 1





      @Nordico You can use description={something containing = and ,.}. This actually didn't work because I had forgotten to wrap the ##1 in the /keyw/#1/.unknown/.style = … line by {}. (Fixed now)

      – Circumscribe
      Dec 5 '18 at 18:58
















    3














    Below, I'm defining the following commands:





    • setkeyword{<keyword>}{<description>} can be used to declare a keyword.


    • getkeyword{<keyword>} retrieves the description you provided.


    • keywordtable{<key1>,<key2>,…} displays a table containing the descriptions corresponding to a comma-separated list of keywords.


    (Note that keywords containing underscores are allowed.)



    documentclass{article}

    usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
    usepackage{etoolbox} %% <- for csuse, csdef, ifcsdef and forcsvlist

    %% Define/retrieve a new keyword:
    newcommandsetkeyword[2]{csdef{keyw@#1}{#2}}
    newcommand*getkeyword[1]{%
    ifcsdef{keyw@#1}{% %% <- if the key is defined...
    csuse{keyw@#1}% %% <- return the description
    }{% %% <- otherwise...
    ??% %% <- question marks
    %errmessage{Undefined key: #1}% %% <- or an ERROR, if you prefer
    }%
    }

    %% Display a table describing a list of keywords:
    newcommand*keywordtable[1]{%
    begin{tabular}{lp{8cm}}
    forcsvlist{tableentry}{#1} %% <- apply tableentry to each value in #1
    end{tabular}%
    }
    newcommand*tableentry[1]{%
    formattableentry{detokenize{#1}}{getkeyword{#1}}%
    }
    newcommandformattableentry[2]{ #1 & #2 \ }

    % %% Declaration of keywords:
    setkeyword{runtype}{Keyword to determine runtype. Can be 1 or 2. par
    I don't want to hardcode this description twiceldots}
    setkeyword{param_1}{Keyword to determine the parameter of runtype = 1}
    setkeyword{param_2}{Keyword to determine the parameter of runtype = 2}

    begin{document}

    section{Runtype 1 description}
    keywordtable{runtype,param_1}

    section{Runtype 2 description}
    keywordtable{runtype,param_2}

    end{document}


    output





    Some remarks





    • setkeyword{<keyword>}{<description>} effectively defines keyw@<keyword> for you, so that it expands to <definition>. You can't use this macro directly because its name contains an @.


    • getkeyword{<keyword>} just calls keyw@<keyword>.

    • I'm using the e-TeX primitive detokenize to print the keyword. This command strips all tokens in its argument of their special meaning (by changing their catcodes), so you can for instance use detokenize{param_1} safely.

    • Without usepackage[T1]{fontenc}, underscores are displayed as " ̇", rather than as "_". You'll probably want to use this package anyway because of the reasons outlined here.

    • I'm using tabularx to create a table that has the same width as the current line width. You can replace linewidth by some other value if you want a different width (or just use tabular, in which case you should replace the X column type by something else).






    A more customisable version



    By request, here is the most customisable version I can think of. This lets you create keywords using setkeyword{<keyword>}{<key1>=<value1>,<key2>=<value2>,…} and retrieve them using getkeyword{<keyword>}{<key>}.
    You can create a table with rows corresponding a set of keywords and columns corresponding to specific keys using



    keywordtable[<key1>,<key2>,…]{<keyword1>,<keyword2>,…}


    I'm using pkgkeys, which is documented in section 82 of the pgf manual.



    documentclass{article}

    usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
    usepackage{pgfkeys} %% <- for everything starting with pgf
    usepackage{etoolbox} %% <- for forcsvlist

    newcommand*{declarekeyword}[1]{%
    pgfkeys{
    /keyw/#1/.is family,
    /keyw/#1/.unknown/.style = {pgfkeyscurrentpath/pgfkeyscurrentname/.initial={##1}},
    }%
    }
    newcommandsetkeyword[2]{%
    declarekeyword{#1}%
    pgfkeys{/keyw/#1/.cd,name=detokenize{#1},#2}%
    }
    newcommand*getkeyword[2]{pgfkeysvalueof{/keyw/#1/#2}}

    %% Display a table describing a list of keywords:
    newcommand*keywordtable[2][name,description]{%
    begin{center}
    begin{tabular}{forcsvlist{getkeyword{@alignment}}{#1}}
    forcsvlist{tableentry[bfseries]{#1}}{@headings}
    forcsvlist{tableentry{#1}}{#2}
    end{tabular}
    end{center}%
    }
    newcommand*tableentry[3]{%
    letkeywcolsepempty
    forcsvlist{keywcolsepdefkeywcolsep{&}formattableentry[#1]{#3}}{#2}\
    }
    newcommand*formattableentry[3]{#1{getkeyword{#2}{#3}}}

    %% "Fake" keywords (control column titles and alignment)
    setkeyword{@headings}{name=Parameter,description=Description,value=Value}
    setkeyword{@alignment}{name=l,description=l,value=r}

    %% Declaration of keywords:
    setkeyword{runtype}{description=A parameter,value=1}
    setkeyword{param_1}{description=Another parameter,value=0}
    setkeyword{param_2}{name=detokenize{PARAM_2},description=A third parameter,value=42}

    begin{document}

    section{Runtype 1 description}
    keywordtable{runtype,param_1}

    section{Runtype 2 description}
    keywordtable[name,value,description]{runtype,param_2}

    end{document}


    output






    share|improve this answer


























    • Awesome! This is a very versatile method and thorough response, thank you very much! It is a bit complex and wordy (at least in setup) for something that feels conceptually simple, but apparently that's just how latex is. Not sure what's the difference between tabular and tabularx, but the later didn't compile correctly for me so went back to the former.

      – Nordico
      Nov 29 '18 at 2:27






    • 1





      @Nordico begin{tabularx}{linewidth}{lX} creates a table of total width linewidth whose second column stretches to accommodate. It was very much inessential to the answer, so I probably shouldn't have used it. (I needed to use either the p{<some width>} or the X column type because one of the entries spans two lines.)

      – Circumscribe
      Nov 29 '18 at 9:04








    • 1





      It is 1-1, but you could for instance have setkeyword call csdef twice to make it 1-2, like I've done here. I can think of a few other (fancier) ways to do this, but those wouldn't really perform any better than this.

      – Circumscribe
      Dec 4 '18 at 21:45






    • 1





      @Nordico See the bottom part of my answer for a ridiculously customisable version.

      – Circumscribe
      Dec 5 '18 at 9:17






    • 1





      @Nordico You can use description={something containing = and ,.}. This actually didn't work because I had forgotten to wrap the ##1 in the /keyw/#1/.unknown/.style = … line by {}. (Fixed now)

      – Circumscribe
      Dec 5 '18 at 18:58














    3












    3








    3







    Below, I'm defining the following commands:





    • setkeyword{<keyword>}{<description>} can be used to declare a keyword.


    • getkeyword{<keyword>} retrieves the description you provided.


    • keywordtable{<key1>,<key2>,…} displays a table containing the descriptions corresponding to a comma-separated list of keywords.


    (Note that keywords containing underscores are allowed.)



    documentclass{article}

    usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
    usepackage{etoolbox} %% <- for csuse, csdef, ifcsdef and forcsvlist

    %% Define/retrieve a new keyword:
    newcommandsetkeyword[2]{csdef{keyw@#1}{#2}}
    newcommand*getkeyword[1]{%
    ifcsdef{keyw@#1}{% %% <- if the key is defined...
    csuse{keyw@#1}% %% <- return the description
    }{% %% <- otherwise...
    ??% %% <- question marks
    %errmessage{Undefined key: #1}% %% <- or an ERROR, if you prefer
    }%
    }

    %% Display a table describing a list of keywords:
    newcommand*keywordtable[1]{%
    begin{tabular}{lp{8cm}}
    forcsvlist{tableentry}{#1} %% <- apply tableentry to each value in #1
    end{tabular}%
    }
    newcommand*tableentry[1]{%
    formattableentry{detokenize{#1}}{getkeyword{#1}}%
    }
    newcommandformattableentry[2]{ #1 & #2 \ }

    % %% Declaration of keywords:
    setkeyword{runtype}{Keyword to determine runtype. Can be 1 or 2. par
    I don't want to hardcode this description twiceldots}
    setkeyword{param_1}{Keyword to determine the parameter of runtype = 1}
    setkeyword{param_2}{Keyword to determine the parameter of runtype = 2}

    begin{document}

    section{Runtype 1 description}
    keywordtable{runtype,param_1}

    section{Runtype 2 description}
    keywordtable{runtype,param_2}

    end{document}


    output





    Some remarks





    • setkeyword{<keyword>}{<description>} effectively defines keyw@<keyword> for you, so that it expands to <definition>. You can't use this macro directly because its name contains an @.


    • getkeyword{<keyword>} just calls keyw@<keyword>.

    • I'm using the e-TeX primitive detokenize to print the keyword. This command strips all tokens in its argument of their special meaning (by changing their catcodes), so you can for instance use detokenize{param_1} safely.

    • Without usepackage[T1]{fontenc}, underscores are displayed as " ̇", rather than as "_". You'll probably want to use this package anyway because of the reasons outlined here.

    • I'm using tabularx to create a table that has the same width as the current line width. You can replace linewidth by some other value if you want a different width (or just use tabular, in which case you should replace the X column type by something else).






    A more customisable version



    By request, here is the most customisable version I can think of. This lets you create keywords using setkeyword{<keyword>}{<key1>=<value1>,<key2>=<value2>,…} and retrieve them using getkeyword{<keyword>}{<key>}.
    You can create a table with rows corresponding a set of keywords and columns corresponding to specific keys using



    keywordtable[<key1>,<key2>,…]{<keyword1>,<keyword2>,…}


    I'm using pkgkeys, which is documented in section 82 of the pgf manual.



    documentclass{article}

    usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
    usepackage{pgfkeys} %% <- for everything starting with pgf
    usepackage{etoolbox} %% <- for forcsvlist

    newcommand*{declarekeyword}[1]{%
    pgfkeys{
    /keyw/#1/.is family,
    /keyw/#1/.unknown/.style = {pgfkeyscurrentpath/pgfkeyscurrentname/.initial={##1}},
    }%
    }
    newcommandsetkeyword[2]{%
    declarekeyword{#1}%
    pgfkeys{/keyw/#1/.cd,name=detokenize{#1},#2}%
    }
    newcommand*getkeyword[2]{pgfkeysvalueof{/keyw/#1/#2}}

    %% Display a table describing a list of keywords:
    newcommand*keywordtable[2][name,description]{%
    begin{center}
    begin{tabular}{forcsvlist{getkeyword{@alignment}}{#1}}
    forcsvlist{tableentry[bfseries]{#1}}{@headings}
    forcsvlist{tableentry{#1}}{#2}
    end{tabular}
    end{center}%
    }
    newcommand*tableentry[3]{%
    letkeywcolsepempty
    forcsvlist{keywcolsepdefkeywcolsep{&}formattableentry[#1]{#3}}{#2}\
    }
    newcommand*formattableentry[3]{#1{getkeyword{#2}{#3}}}

    %% "Fake" keywords (control column titles and alignment)
    setkeyword{@headings}{name=Parameter,description=Description,value=Value}
    setkeyword{@alignment}{name=l,description=l,value=r}

    %% Declaration of keywords:
    setkeyword{runtype}{description=A parameter,value=1}
    setkeyword{param_1}{description=Another parameter,value=0}
    setkeyword{param_2}{name=detokenize{PARAM_2},description=A third parameter,value=42}

    begin{document}

    section{Runtype 1 description}
    keywordtable{runtype,param_1}

    section{Runtype 2 description}
    keywordtable[name,value,description]{runtype,param_2}

    end{document}


    output






    share|improve this answer















    Below, I'm defining the following commands:





    • setkeyword{<keyword>}{<description>} can be used to declare a keyword.


    • getkeyword{<keyword>} retrieves the description you provided.


    • keywordtable{<key1>,<key2>,…} displays a table containing the descriptions corresponding to a comma-separated list of keywords.


    (Note that keywords containing underscores are allowed.)



    documentclass{article}

    usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
    usepackage{etoolbox} %% <- for csuse, csdef, ifcsdef and forcsvlist

    %% Define/retrieve a new keyword:
    newcommandsetkeyword[2]{csdef{keyw@#1}{#2}}
    newcommand*getkeyword[1]{%
    ifcsdef{keyw@#1}{% %% <- if the key is defined...
    csuse{keyw@#1}% %% <- return the description
    }{% %% <- otherwise...
    ??% %% <- question marks
    %errmessage{Undefined key: #1}% %% <- or an ERROR, if you prefer
    }%
    }

    %% Display a table describing a list of keywords:
    newcommand*keywordtable[1]{%
    begin{tabular}{lp{8cm}}
    forcsvlist{tableentry}{#1} %% <- apply tableentry to each value in #1
    end{tabular}%
    }
    newcommand*tableentry[1]{%
    formattableentry{detokenize{#1}}{getkeyword{#1}}%
    }
    newcommandformattableentry[2]{ #1 & #2 \ }

    % %% Declaration of keywords:
    setkeyword{runtype}{Keyword to determine runtype. Can be 1 or 2. par
    I don't want to hardcode this description twiceldots}
    setkeyword{param_1}{Keyword to determine the parameter of runtype = 1}
    setkeyword{param_2}{Keyword to determine the parameter of runtype = 2}

    begin{document}

    section{Runtype 1 description}
    keywordtable{runtype,param_1}

    section{Runtype 2 description}
    keywordtable{runtype,param_2}

    end{document}


    output





    Some remarks





    • setkeyword{<keyword>}{<description>} effectively defines keyw@<keyword> for you, so that it expands to <definition>. You can't use this macro directly because its name contains an @.


    • getkeyword{<keyword>} just calls keyw@<keyword>.

    • I'm using the e-TeX primitive detokenize to print the keyword. This command strips all tokens in its argument of their special meaning (by changing their catcodes), so you can for instance use detokenize{param_1} safely.

    • Without usepackage[T1]{fontenc}, underscores are displayed as " ̇", rather than as "_". You'll probably want to use this package anyway because of the reasons outlined here.

    • I'm using tabularx to create a table that has the same width as the current line width. You can replace linewidth by some other value if you want a different width (or just use tabular, in which case you should replace the X column type by something else).






    A more customisable version



    By request, here is the most customisable version I can think of. This lets you create keywords using setkeyword{<keyword>}{<key1>=<value1>,<key2>=<value2>,…} and retrieve them using getkeyword{<keyword>}{<key>}.
    You can create a table with rows corresponding a set of keywords and columns corresponding to specific keys using



    keywordtable[<key1>,<key2>,…]{<keyword1>,<keyword2>,…}


    I'm using pkgkeys, which is documented in section 82 of the pgf manual.



    documentclass{article}

    usepackage[T1]{fontenc} %% <- necessary for _ to be displayed correctly
    usepackage{pgfkeys} %% <- for everything starting with pgf
    usepackage{etoolbox} %% <- for forcsvlist

    newcommand*{declarekeyword}[1]{%
    pgfkeys{
    /keyw/#1/.is family,
    /keyw/#1/.unknown/.style = {pgfkeyscurrentpath/pgfkeyscurrentname/.initial={##1}},
    }%
    }
    newcommandsetkeyword[2]{%
    declarekeyword{#1}%
    pgfkeys{/keyw/#1/.cd,name=detokenize{#1},#2}%
    }
    newcommand*getkeyword[2]{pgfkeysvalueof{/keyw/#1/#2}}

    %% Display a table describing a list of keywords:
    newcommand*keywordtable[2][name,description]{%
    begin{center}
    begin{tabular}{forcsvlist{getkeyword{@alignment}}{#1}}
    forcsvlist{tableentry[bfseries]{#1}}{@headings}
    forcsvlist{tableentry{#1}}{#2}
    end{tabular}
    end{center}%
    }
    newcommand*tableentry[3]{%
    letkeywcolsepempty
    forcsvlist{keywcolsepdefkeywcolsep{&}formattableentry[#1]{#3}}{#2}\
    }
    newcommand*formattableentry[3]{#1{getkeyword{#2}{#3}}}

    %% "Fake" keywords (control column titles and alignment)
    setkeyword{@headings}{name=Parameter,description=Description,value=Value}
    setkeyword{@alignment}{name=l,description=l,value=r}

    %% Declaration of keywords:
    setkeyword{runtype}{description=A parameter,value=1}
    setkeyword{param_1}{description=Another parameter,value=0}
    setkeyword{param_2}{name=detokenize{PARAM_2},description=A third parameter,value=42}

    begin{document}

    section{Runtype 1 description}
    keywordtable{runtype,param_1}

    section{Runtype 2 description}
    keywordtable[name,value,description]{runtype,param_2}

    end{document}


    output







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Dec 5 '18 at 18:55

























    answered Nov 27 '18 at 23:40









    CircumscribeCircumscribe

    7,28121541




    7,28121541













    • Awesome! This is a very versatile method and thorough response, thank you very much! It is a bit complex and wordy (at least in setup) for something that feels conceptually simple, but apparently that's just how latex is. Not sure what's the difference between tabular and tabularx, but the later didn't compile correctly for me so went back to the former.

      – Nordico
      Nov 29 '18 at 2:27






    • 1





      @Nordico begin{tabularx}{linewidth}{lX} creates a table of total width linewidth whose second column stretches to accommodate. It was very much inessential to the answer, so I probably shouldn't have used it. (I needed to use either the p{<some width>} or the X column type because one of the entries spans two lines.)

      – Circumscribe
      Nov 29 '18 at 9:04








    • 1





      It is 1-1, but you could for instance have setkeyword call csdef twice to make it 1-2, like I've done here. I can think of a few other (fancier) ways to do this, but those wouldn't really perform any better than this.

      – Circumscribe
      Dec 4 '18 at 21:45






    • 1





      @Nordico See the bottom part of my answer for a ridiculously customisable version.

      – Circumscribe
      Dec 5 '18 at 9:17






    • 1





      @Nordico You can use description={something containing = and ,.}. This actually didn't work because I had forgotten to wrap the ##1 in the /keyw/#1/.unknown/.style = … line by {}. (Fixed now)

      – Circumscribe
      Dec 5 '18 at 18:58



















    • Awesome! This is a very versatile method and thorough response, thank you very much! It is a bit complex and wordy (at least in setup) for something that feels conceptually simple, but apparently that's just how latex is. Not sure what's the difference between tabular and tabularx, but the later didn't compile correctly for me so went back to the former.

      – Nordico
      Nov 29 '18 at 2:27






    • 1





      @Nordico begin{tabularx}{linewidth}{lX} creates a table of total width linewidth whose second column stretches to accommodate. It was very much inessential to the answer, so I probably shouldn't have used it. (I needed to use either the p{<some width>} or the X column type because one of the entries spans two lines.)

      – Circumscribe
      Nov 29 '18 at 9:04








    • 1





      It is 1-1, but you could for instance have setkeyword call csdef twice to make it 1-2, like I've done here. I can think of a few other (fancier) ways to do this, but those wouldn't really perform any better than this.

      – Circumscribe
      Dec 4 '18 at 21:45






    • 1





      @Nordico See the bottom part of my answer for a ridiculously customisable version.

      – Circumscribe
      Dec 5 '18 at 9:17






    • 1





      @Nordico You can use description={something containing = and ,.}. This actually didn't work because I had forgotten to wrap the ##1 in the /keyw/#1/.unknown/.style = … line by {}. (Fixed now)

      – Circumscribe
      Dec 5 '18 at 18:58

















    Awesome! This is a very versatile method and thorough response, thank you very much! It is a bit complex and wordy (at least in setup) for something that feels conceptually simple, but apparently that's just how latex is. Not sure what's the difference between tabular and tabularx, but the later didn't compile correctly for me so went back to the former.

    – Nordico
    Nov 29 '18 at 2:27





    Awesome! This is a very versatile method and thorough response, thank you very much! It is a bit complex and wordy (at least in setup) for something that feels conceptually simple, but apparently that's just how latex is. Not sure what's the difference between tabular and tabularx, but the later didn't compile correctly for me so went back to the former.

    – Nordico
    Nov 29 '18 at 2:27




    1




    1





    @Nordico begin{tabularx}{linewidth}{lX} creates a table of total width linewidth whose second column stretches to accommodate. It was very much inessential to the answer, so I probably shouldn't have used it. (I needed to use either the p{<some width>} or the X column type because one of the entries spans two lines.)

    – Circumscribe
    Nov 29 '18 at 9:04







    @Nordico begin{tabularx}{linewidth}{lX} creates a table of total width linewidth whose second column stretches to accommodate. It was very much inessential to the answer, so I probably shouldn't have used it. (I needed to use either the p{<some width>} or the X column type because one of the entries spans two lines.)

    – Circumscribe
    Nov 29 '18 at 9:04






    1




    1





    It is 1-1, but you could for instance have setkeyword call csdef twice to make it 1-2, like I've done here. I can think of a few other (fancier) ways to do this, but those wouldn't really perform any better than this.

    – Circumscribe
    Dec 4 '18 at 21:45





    It is 1-1, but you could for instance have setkeyword call csdef twice to make it 1-2, like I've done here. I can think of a few other (fancier) ways to do this, but those wouldn't really perform any better than this.

    – Circumscribe
    Dec 4 '18 at 21:45




    1




    1





    @Nordico See the bottom part of my answer for a ridiculously customisable version.

    – Circumscribe
    Dec 5 '18 at 9:17





    @Nordico See the bottom part of my answer for a ridiculously customisable version.

    – Circumscribe
    Dec 5 '18 at 9:17




    1




    1





    @Nordico You can use description={something containing = and ,.}. This actually didn't work because I had forgotten to wrap the ##1 in the /keyw/#1/.unknown/.style = … line by {}. (Fixed now)

    – Circumscribe
    Dec 5 '18 at 18:58





    @Nordico You can use description={something containing = and ,.}. This actually didn't work because I had forgotten to wrap the ##1 in the /keyw/#1/.unknown/.style = … line by {}. (Fixed now)

    – Circumscribe
    Dec 5 '18 at 18:58











    2














    documentclass[12pt]{article}
    newcommandzzz{%
    runtype & Keyword to determine runtype. Can be 1 or 2. \
    & I don't want to hardcode this description twice...}
    begin{document}
    section{Runtype 1 description}
    begin{table}[ht]
    begin{center}
    begin{tabular}{ l l }
    zzz\
    param_1 & Keyword to determine the parameter of runtype = 1 \
    end{tabular}
    end{center}
    end{table}

    section{Runtype 2 description}
    begin{table}[ht]
    begin{center}
    begin{tabular}{ l l }
    zzz\
    param_2 & Keyword to determine the parameter of runtype = 2 \
    end{tabular}
    end{center}
    end{table}
    end{document}


    enter image description here






    share|improve this answer
























    • Ok, this works but feels like using a cannon to kill a fly. More precisely: I need to use this with around a hundred keywords, is defining a hundred newcommand to use as a "reference dictionary" advisable? How can I use descriptive names (tablekey_keyname) without using underscores?

      – Nordico
      Nov 27 '18 at 21:20











    • @Nordico As to how to use underscores in a command name, options are limited: 1) change catcode of _ (not recommended, as it breaks subscript math), or 2) csdef and csuse with the etoolbox package (recommended if you insist on underscore in name)

      – Steven B. Segletes
      Nov 27 '18 at 21:24













    • I mean, not necessarily an underscore, it can be other symbol ("tablekey.keyname") or a way of structuring the commands (like an equivalent to C++ namespaces, so I could do "tablekey::keyname"), anything that makes it more human readable/usable than just altogether "tablekeykeyname".

      – Nordico
      Nov 27 '18 at 21:29








    • 1





      @Nordico In my example, add catcode`:=11 as the first line after documentclass, This changes : to be a "letter". Then newcommandzz:z{...} can be defined and later used as zz:z. What I don't know is if this breaks anything (e.g., spacing, hyphenation), if you use : as a normal character.

      – Steven B. Segletes
      Nov 27 '18 at 21:36








    • 1





      I thought zzz was reserved for @David Carlisle ;-)

      – Raoul Kessels
      Nov 28 '18 at 11:12
















    2














    documentclass[12pt]{article}
    newcommandzzz{%
    runtype & Keyword to determine runtype. Can be 1 or 2. \
    & I don't want to hardcode this description twice...}
    begin{document}
    section{Runtype 1 description}
    begin{table}[ht]
    begin{center}
    begin{tabular}{ l l }
    zzz\
    param_1 & Keyword to determine the parameter of runtype = 1 \
    end{tabular}
    end{center}
    end{table}

    section{Runtype 2 description}
    begin{table}[ht]
    begin{center}
    begin{tabular}{ l l }
    zzz\
    param_2 & Keyword to determine the parameter of runtype = 2 \
    end{tabular}
    end{center}
    end{table}
    end{document}


    enter image description here






    share|improve this answer
























    • Ok, this works but feels like using a cannon to kill a fly. More precisely: I need to use this with around a hundred keywords, is defining a hundred newcommand to use as a "reference dictionary" advisable? How can I use descriptive names (tablekey_keyname) without using underscores?

      – Nordico
      Nov 27 '18 at 21:20











    • @Nordico As to how to use underscores in a command name, options are limited: 1) change catcode of _ (not recommended, as it breaks subscript math), or 2) csdef and csuse with the etoolbox package (recommended if you insist on underscore in name)

      – Steven B. Segletes
      Nov 27 '18 at 21:24













    • I mean, not necessarily an underscore, it can be other symbol ("tablekey.keyname") or a way of structuring the commands (like an equivalent to C++ namespaces, so I could do "tablekey::keyname"), anything that makes it more human readable/usable than just altogether "tablekeykeyname".

      – Nordico
      Nov 27 '18 at 21:29








    • 1





      @Nordico In my example, add catcode`:=11 as the first line after documentclass, This changes : to be a "letter". Then newcommandzz:z{...} can be defined and later used as zz:z. What I don't know is if this breaks anything (e.g., spacing, hyphenation), if you use : as a normal character.

      – Steven B. Segletes
      Nov 27 '18 at 21:36








    • 1





      I thought zzz was reserved for @David Carlisle ;-)

      – Raoul Kessels
      Nov 28 '18 at 11:12














    2












    2








    2







    documentclass[12pt]{article}
    newcommandzzz{%
    runtype & Keyword to determine runtype. Can be 1 or 2. \
    & I don't want to hardcode this description twice...}
    begin{document}
    section{Runtype 1 description}
    begin{table}[ht]
    begin{center}
    begin{tabular}{ l l }
    zzz\
    param_1 & Keyword to determine the parameter of runtype = 1 \
    end{tabular}
    end{center}
    end{table}

    section{Runtype 2 description}
    begin{table}[ht]
    begin{center}
    begin{tabular}{ l l }
    zzz\
    param_2 & Keyword to determine the parameter of runtype = 2 \
    end{tabular}
    end{center}
    end{table}
    end{document}


    enter image description here






    share|improve this answer













    documentclass[12pt]{article}
    newcommandzzz{%
    runtype & Keyword to determine runtype. Can be 1 or 2. \
    & I don't want to hardcode this description twice...}
    begin{document}
    section{Runtype 1 description}
    begin{table}[ht]
    begin{center}
    begin{tabular}{ l l }
    zzz\
    param_1 & Keyword to determine the parameter of runtype = 1 \
    end{tabular}
    end{center}
    end{table}

    section{Runtype 2 description}
    begin{table}[ht]
    begin{center}
    begin{tabular}{ l l }
    zzz\
    param_2 & Keyword to determine the parameter of runtype = 2 \
    end{tabular}
    end{center}
    end{table}
    end{document}


    enter image description here







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 27 '18 at 21:09









    Steven B. SegletesSteven B. Segletes

    158k9204411




    158k9204411













    • Ok, this works but feels like using a cannon to kill a fly. More precisely: I need to use this with around a hundred keywords, is defining a hundred newcommand to use as a "reference dictionary" advisable? How can I use descriptive names (tablekey_keyname) without using underscores?

      – Nordico
      Nov 27 '18 at 21:20











    • @Nordico As to how to use underscores in a command name, options are limited: 1) change catcode of _ (not recommended, as it breaks subscript math), or 2) csdef and csuse with the etoolbox package (recommended if you insist on underscore in name)

      – Steven B. Segletes
      Nov 27 '18 at 21:24













    • I mean, not necessarily an underscore, it can be other symbol ("tablekey.keyname") or a way of structuring the commands (like an equivalent to C++ namespaces, so I could do "tablekey::keyname"), anything that makes it more human readable/usable than just altogether "tablekeykeyname".

      – Nordico
      Nov 27 '18 at 21:29








    • 1





      @Nordico In my example, add catcode`:=11 as the first line after documentclass, This changes : to be a "letter". Then newcommandzz:z{...} can be defined and later used as zz:z. What I don't know is if this breaks anything (e.g., spacing, hyphenation), if you use : as a normal character.

      – Steven B. Segletes
      Nov 27 '18 at 21:36








    • 1





      I thought zzz was reserved for @David Carlisle ;-)

      – Raoul Kessels
      Nov 28 '18 at 11:12



















    • Ok, this works but feels like using a cannon to kill a fly. More precisely: I need to use this with around a hundred keywords, is defining a hundred newcommand to use as a "reference dictionary" advisable? How can I use descriptive names (tablekey_keyname) without using underscores?

      – Nordico
      Nov 27 '18 at 21:20











    • @Nordico As to how to use underscores in a command name, options are limited: 1) change catcode of _ (not recommended, as it breaks subscript math), or 2) csdef and csuse with the etoolbox package (recommended if you insist on underscore in name)

      – Steven B. Segletes
      Nov 27 '18 at 21:24













    • I mean, not necessarily an underscore, it can be other symbol ("tablekey.keyname") or a way of structuring the commands (like an equivalent to C++ namespaces, so I could do "tablekey::keyname"), anything that makes it more human readable/usable than just altogether "tablekeykeyname".

      – Nordico
      Nov 27 '18 at 21:29








    • 1





      @Nordico In my example, add catcode`:=11 as the first line after documentclass, This changes : to be a "letter". Then newcommandzz:z{...} can be defined and later used as zz:z. What I don't know is if this breaks anything (e.g., spacing, hyphenation), if you use : as a normal character.

      – Steven B. Segletes
      Nov 27 '18 at 21:36








    • 1





      I thought zzz was reserved for @David Carlisle ;-)

      – Raoul Kessels
      Nov 28 '18 at 11:12

















    Ok, this works but feels like using a cannon to kill a fly. More precisely: I need to use this with around a hundred keywords, is defining a hundred newcommand to use as a "reference dictionary" advisable? How can I use descriptive names (tablekey_keyname) without using underscores?

    – Nordico
    Nov 27 '18 at 21:20





    Ok, this works but feels like using a cannon to kill a fly. More precisely: I need to use this with around a hundred keywords, is defining a hundred newcommand to use as a "reference dictionary" advisable? How can I use descriptive names (tablekey_keyname) without using underscores?

    – Nordico
    Nov 27 '18 at 21:20













    @Nordico As to how to use underscores in a command name, options are limited: 1) change catcode of _ (not recommended, as it breaks subscript math), or 2) csdef and csuse with the etoolbox package (recommended if you insist on underscore in name)

    – Steven B. Segletes
    Nov 27 '18 at 21:24







    @Nordico As to how to use underscores in a command name, options are limited: 1) change catcode of _ (not recommended, as it breaks subscript math), or 2) csdef and csuse with the etoolbox package (recommended if you insist on underscore in name)

    – Steven B. Segletes
    Nov 27 '18 at 21:24















    I mean, not necessarily an underscore, it can be other symbol ("tablekey.keyname") or a way of structuring the commands (like an equivalent to C++ namespaces, so I could do "tablekey::keyname"), anything that makes it more human readable/usable than just altogether "tablekeykeyname".

    – Nordico
    Nov 27 '18 at 21:29







    I mean, not necessarily an underscore, it can be other symbol ("tablekey.keyname") or a way of structuring the commands (like an equivalent to C++ namespaces, so I could do "tablekey::keyname"), anything that makes it more human readable/usable than just altogether "tablekeykeyname".

    – Nordico
    Nov 27 '18 at 21:29






    1




    1





    @Nordico In my example, add catcode`:=11 as the first line after documentclass, This changes : to be a "letter". Then newcommandzz:z{...} can be defined and later used as zz:z. What I don't know is if this breaks anything (e.g., spacing, hyphenation), if you use : as a normal character.

    – Steven B. Segletes
    Nov 27 '18 at 21:36







    @Nordico In my example, add catcode`:=11 as the first line after documentclass, This changes : to be a "letter". Then newcommandzz:z{...} can be defined and later used as zz:z. What I don't know is if this breaks anything (e.g., spacing, hyphenation), if you use : as a normal character.

    – Steven B. Segletes
    Nov 27 '18 at 21:36






    1




    1





    I thought zzz was reserved for @David Carlisle ;-)

    – Raoul Kessels
    Nov 28 '18 at 11:12





    I thought zzz was reserved for @David Carlisle ;-)

    – Raoul Kessels
    Nov 28 '18 at 11:12











    1














    It depends on where you want to first key the description you want to repeat.



    Probably the best place is in the document preamble or in an external file that you can input.



    documentclass{article}
    usepackage{xparse}

    % a few line of code for setting up the system
    ExplSyntaxOn

    NewDocumentCommand{newdesc}{mm}
    {% #1 is a key, #2 is the description
    prop_gput:Nnn g_nordico_descriptions_plist { #1 } { #2 }
    }

    NewDocumentCommand{getdesc}{m}
    {% #1 is a key
    prop_if_in:NnTF g_nordico_descriptions_plist { #1 }
    { prop_item:Nn g_nordico_descriptions_plist { #1 } }
    { ???~non~existent~description~??? }
    }

    prop_new:N g_nordico_descriptions_plist

    ExplSyntaxOff

    % the descriptions (they can go in an external file
    % say desc.tex and here you'd do input{desc}

    newdesc{A}{I don't want to hardcode this description twice...}

    begin{document}

    section{Runtype 1 description}
    begin{center}
    begin{tabular}{ l l }
    runtype & Keyword to determine runtype. Can be 1 or 2. \
    & getdesc{A} \
    param_1 & Keyword to determine the parameter of runtype = 1 \
    end{tabular}
    end{center}

    section{Runtype 2 description}
    begin{center}
    begin{tabular}{ l l }
    runtype & Keyword to determine runtype. Can be 1 or 2. \
    & getdesc{A} \
    param_2 & Keyword to determine the parameter of runtype = 2 \
    end{tabular}
    end{center}

    end{document}


    Note that it is not at all necessary to place a tabular in a floating table environment (which might make the tabular go to another page).



    enter image description here






    share|improve this answer




























      1














      It depends on where you want to first key the description you want to repeat.



      Probably the best place is in the document preamble or in an external file that you can input.



      documentclass{article}
      usepackage{xparse}

      % a few line of code for setting up the system
      ExplSyntaxOn

      NewDocumentCommand{newdesc}{mm}
      {% #1 is a key, #2 is the description
      prop_gput:Nnn g_nordico_descriptions_plist { #1 } { #2 }
      }

      NewDocumentCommand{getdesc}{m}
      {% #1 is a key
      prop_if_in:NnTF g_nordico_descriptions_plist { #1 }
      { prop_item:Nn g_nordico_descriptions_plist { #1 } }
      { ???~non~existent~description~??? }
      }

      prop_new:N g_nordico_descriptions_plist

      ExplSyntaxOff

      % the descriptions (they can go in an external file
      % say desc.tex and here you'd do input{desc}

      newdesc{A}{I don't want to hardcode this description twice...}

      begin{document}

      section{Runtype 1 description}
      begin{center}
      begin{tabular}{ l l }
      runtype & Keyword to determine runtype. Can be 1 or 2. \
      & getdesc{A} \
      param_1 & Keyword to determine the parameter of runtype = 1 \
      end{tabular}
      end{center}

      section{Runtype 2 description}
      begin{center}
      begin{tabular}{ l l }
      runtype & Keyword to determine runtype. Can be 1 or 2. \
      & getdesc{A} \
      param_2 & Keyword to determine the parameter of runtype = 2 \
      end{tabular}
      end{center}

      end{document}


      Note that it is not at all necessary to place a tabular in a floating table environment (which might make the tabular go to another page).



      enter image description here






      share|improve this answer


























        1












        1








        1







        It depends on where you want to first key the description you want to repeat.



        Probably the best place is in the document preamble or in an external file that you can input.



        documentclass{article}
        usepackage{xparse}

        % a few line of code for setting up the system
        ExplSyntaxOn

        NewDocumentCommand{newdesc}{mm}
        {% #1 is a key, #2 is the description
        prop_gput:Nnn g_nordico_descriptions_plist { #1 } { #2 }
        }

        NewDocumentCommand{getdesc}{m}
        {% #1 is a key
        prop_if_in:NnTF g_nordico_descriptions_plist { #1 }
        { prop_item:Nn g_nordico_descriptions_plist { #1 } }
        { ???~non~existent~description~??? }
        }

        prop_new:N g_nordico_descriptions_plist

        ExplSyntaxOff

        % the descriptions (they can go in an external file
        % say desc.tex and here you'd do input{desc}

        newdesc{A}{I don't want to hardcode this description twice...}

        begin{document}

        section{Runtype 1 description}
        begin{center}
        begin{tabular}{ l l }
        runtype & Keyword to determine runtype. Can be 1 or 2. \
        & getdesc{A} \
        param_1 & Keyword to determine the parameter of runtype = 1 \
        end{tabular}
        end{center}

        section{Runtype 2 description}
        begin{center}
        begin{tabular}{ l l }
        runtype & Keyword to determine runtype. Can be 1 or 2. \
        & getdesc{A} \
        param_2 & Keyword to determine the parameter of runtype = 2 \
        end{tabular}
        end{center}

        end{document}


        Note that it is not at all necessary to place a tabular in a floating table environment (which might make the tabular go to another page).



        enter image description here






        share|improve this answer













        It depends on where you want to first key the description you want to repeat.



        Probably the best place is in the document preamble or in an external file that you can input.



        documentclass{article}
        usepackage{xparse}

        % a few line of code for setting up the system
        ExplSyntaxOn

        NewDocumentCommand{newdesc}{mm}
        {% #1 is a key, #2 is the description
        prop_gput:Nnn g_nordico_descriptions_plist { #1 } { #2 }
        }

        NewDocumentCommand{getdesc}{m}
        {% #1 is a key
        prop_if_in:NnTF g_nordico_descriptions_plist { #1 }
        { prop_item:Nn g_nordico_descriptions_plist { #1 } }
        { ???~non~existent~description~??? }
        }

        prop_new:N g_nordico_descriptions_plist

        ExplSyntaxOff

        % the descriptions (they can go in an external file
        % say desc.tex and here you'd do input{desc}

        newdesc{A}{I don't want to hardcode this description twice...}

        begin{document}

        section{Runtype 1 description}
        begin{center}
        begin{tabular}{ l l }
        runtype & Keyword to determine runtype. Can be 1 or 2. \
        & getdesc{A} \
        param_1 & Keyword to determine the parameter of runtype = 1 \
        end{tabular}
        end{center}

        section{Runtype 2 description}
        begin{center}
        begin{tabular}{ l l }
        runtype & Keyword to determine runtype. Can be 1 or 2. \
        & getdesc{A} \
        param_2 & Keyword to determine the parameter of runtype = 2 \
        end{tabular}
        end{center}

        end{document}


        Note that it is not at all necessary to place a tabular in a floating table environment (which might make the tabular go to another page).



        enter image description here







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 28 '18 at 0:07









        egregegreg

        726k8819193228




        726k8819193228






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f462072%2fhow-to-repeat-the-same-content-in-different-tables%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Contact image not getting when fetch all contact list from iPhone by CNContact

            count number of partitions of a set with n elements into k subsets

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks