2

Following on from Arbitrary named counter, referenced, which was answered very comprehensively, I have a follow up question. This one's difficult to describe so my searching around the internet and StackExchange may not have found any existing answers, apologies if so, most happy to be directed towards previous answers if so.

Basically, if I now have my beautifully arbitrarily labelled table (see Arbitrary named counter, referenced) thus:

[table begin preamble]
\project{ProjectAlpha} & [Description of alpha.] \\
\project{ProjectBeta}  & [Description of beta.] \\
\project{ProjectGamma} & [Description of gamma.] \\
[end table code]

Then what I need to do in other parts of the document is quote the entire table row. I.e., in other parts of the documents, I might need to show a table with just:

[table begin preamble]
ProjectBeta & [Description of beta.] \\
[end table code]

And there's no way I should reproduce that by hand since the underlying description will be changing regularly, so I'd want to write once, propagate everywhere (external documents too, using xr).

Is there any way to do this? Maybe similar to how \pageref{} works by displaying the page number on which an object occurs, whether it's possible to show the entire row on which a label exists?

1 Answer 1

1

If you're always going to define the project and its description before re-using it, then you can use the following setup:

enter image description here

\documentclass{article}

\newcommand{\projectnamestyle}[1]{\textsc{#1}}
\newcommand{\projectnamerefstyle}[1]{[\textsc{#1}]}
\newcommand{\projectdescstyle}[1]{\textnormal{#1}}
\newcommand{\projectdescrefstyle}[1]{[\textnormal{#1}]}
\makeatletter
\newcommand{\project}[1]{%
  \projectnamestyle{#1}%
  \global\@namedef{project@name@#1}{\projectnamerefstyle{#1}}%
}
\newcommand{\projectref}[1]{%
  \expandafter\ifx\csname project@name@#1\endcsname\relax
    \textbf{??}%
  \else
    \@nameuse{project@name@#1}%
  \fi}
\newcommand{\projectdesc}[2][\relax]{%
  \projectdescrefstyle{#2}%
  \def\@project{#1}%
  \expandafter\ifx\@project\relax\else
    \expandafter\ifx\csname project@name@#1\endcsname\relax
      \typeout{Project "#1" does not exist.}%
    \else
      \global\@namedef{project@desc@#1}{\projectdescrefstyle{#2}}%
    \fi
  \fi
}
\newcommand{\projectdescref}[1]{%
  \expandafter\ifx\csname project@desc@#1\endcsname\relax
    \textbf{??}%
  \else
    \@nameuse{project@desc@#1}%
  \fi}
\makeatother

\begin{document}
\begin{tabular}{ll}
  \project{Project-Quick}  & \projectdesc[Project-Quick]{Details hereA.}  \\
  \project{Task-Brown}     & \projectdesc[Task-Brown]{Details hereB.}     \\
  \project{Todo-Fox}       & \projectdesc{Details hereC.}                 \\
  \project{Project-Jumped} & \projectdesc[Project-Jumped]{Details hereD.}
\end{tabular}

\projectref{Project-Quick} (description: \projectdescref{Project-Quick}) has been completed \par
\projectref{Task-Brown} (description: \projectdescref{Task-Brown}) has been completed \par
\projectref{Todo-Fox} (description: \projectdescref{Todo-Fox}) is still ongoing \par
\projectref{Project-Jumped} (description: \projectdescref{Project-Jumped}) has been completed
\end{document}

The following provides a little more leeway in terms of the project placement via zref property lists:

enter image description here

\documentclass{article}

\usepackage{zref}% http://ctan.org/pkg/zref

\newcommand{\projectnamerefstyle}[1]{[\textsc{#1}]}
\newcommand{\projectdescrefstyle}[1]{[\textnormal{#1}]}

\makeatletter
\zref@newlist{project}
\zref@newprop{projectname}[\textbf{??}]{-project name-}
\zref@newprop{projectdescription}[\textbf{??}]{-project description-}
\zref@addprops{project}{projectname, projectdescription}
\newcommand{\project}[1]{\zref@setcurrent{projectname}{#1}}%
\newcommand{\projectdesc}[1]{\zref@setcurrent{projectdescription}{#1}}
\newcommand{\projectlabel}[1]{%
  \zref@labelbylist{#1}{project}% Store project information
  \zref@setcurrent{projectname}{\textbf{??}}% Clear project name
  \zref@setcurrent{projectdescription}{\textbf{??}}}% Clear project description
\newcommand{\projectref}[1]{\projectnamerefstyle{\zref@extractdefault{#1}{projectname}{\textbf{??}}}\zref@refused{#1}}
\newcommand{\projectdescref}[1]{\projectdescrefstyle{\zref@extractdefault{#1}{projectdescription}{\textbf{??}}}\zref@refused{#1}}
\makeatother

\begin{document}

\begin{tabular}{ll}
  \projectref{quick}  & \projectdescref{quick} \\
  \projectref{brown}  & \projectdescref{brown} \\
  \projectref{fox}    & \projectdescref{fox}   \\
  \projectref{jumped} & \projectdescref{jumped}
\end{tabular}

\project{Project-Quick} \projectdesc{Details hereA.}\projectlabel{quick}
\project{Task-Brown}    \projectdesc{Details hereB.}\projectlabel{brown}
\project{Todo-Fox}      \projectdesc{Details hereC.}\projectlabel{fox}
\project{Project-Jumped}\projectdesc{Details hereD.}\projectlabel{jumped}

\end{document}

Each project is declared using \project and \projectdesc. Information regarding these two attributes are stored when you execute \projectlabel{<label>}, and recalled using \projectref{<label>} and \projectdescref{<label>}. This approach might be useful if you keep a separate file containing all your project in a \project{..}\projectdesc{...}\projectlabel{.} format.

Of course, the interface can be changed if needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.