3

I am writing a book, where I have a lot of persons and some of them has the same name. I have constructed a new documentCommand: \createPerson, that produces a setup for some basic attributes of the person and builds relevant references that can be used to get e.g. the full name or the called name of a person. It also returns a unique id of the person, so he can be identified. An example of the output could be:

\nameref{CarlWilhelmLarsen1867} --> outputs --> Carl Wilhelm Larsen(315)

The final output of the person could look like this: enter image description here

Now for the question. Is it possible to create a index of where CarlWilhelmLarsen1867 is mentioned in the book and if so, then how?

A minimum example of how I create the person is here. I know it is a little long. However, I hope you can mange it. I have created the commands: createPerson and textlabel. I am hoping that these maybe can be used to create the foundation for the index. But any way, you probably have a good solution.

\documentclass{article}
\usepackage{tikz}
\usepackage{datetime}
\usepackage[danish]{varioref}
\usepackage{hyperref}
\usepackage{xifthen}
\RequirePackage[framemethod=TikZ]{mdframed}
\usepackage{multirow, tabularx}
\usepackage[]{units}
\usepackage{xparse}
\usepackage{adjustbox}

%=========================================================================
%                             CREATE PERSON NEW
%=========================================================================
%Arguments: 
%   1)  MANDATORY   - Image destination
%   2)  [OPTIONAL]  - Called name
%   3)  MANDATORY   - Reference to the current full name
%   4)  [OPTIONAL]  - Full birth name
%   5)  MANDATORY   - Uniqueue Reference number
%   6)  [OPTIONAL]  - Birth date in the format of dd. mmm. yyyy
%   7)  <OPTIONAL>  - Death date in the format of dd. mmm. yyyy
\NewDocumentCommand\createPerson{r<>omomo+d<>}
{
    \begin{mdframed}[style=whiteBox]%
        \profileImage[width=0.25\textwidth]{Images/People/ProfileImages/#1}
        \begin{tabularx}{0.75\textwidth}[t]{lXrc}%
            % Row one
            Navn:   &   \nameref{#3}    & \textlabel{#5}{PERSON_ID:#3}    & $\Re$%
            %Create new row if needed
            \IfNoValueTF{#2}%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}}%
                        {\\}}%
                    {\\}}%
                {\\}%
            % Row two
            \IfNoValueTF{#4}%
                % If no birth name
                {\IfNoValueTF{#2}%
                    % If no called name
                    {&&}%
                    % If a called name
                    {Kaldenavn: & \textlabel{#2}{KN:#3} &}}%
                %If a birth name
                {Fødenavn: & #4 &}%
                %
                \IfNoValueTF{#6}%
                       % If no birth date
                       {\IfNoValueTF{#7}{}{\textlabel{#7}{DD:#3} & \cross}}%
                       {\textlabel{#6}{FD:#3} & $\star$}%
            % Create new row if needed    
            \IfNoValueTF{#2}%
                {%
                \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                }%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                    }%
                    {\\}%
                }%
            % Row three
            \IfNoValueTF{#2}%
                % If no called name
                {%
                    \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {&&}%
                        }%
                }%
                % If a called name
                {\IfNoValueTF{#4}%
                    % If no birth name
                    {
                        \IfNoValueTF{#6}%
                            {}%
                            {\IfNoValueTF{#7}%
                                {}%
                                {&&}%
                            }%
                    }%
                    %If birth name
                    {Kaldenavn: & \textlabel{#2}{KN:#3} &}%
                }%
            %
            \IfNoValueTF{#7}%
                       % If no death date
                       {}%
                       {\IfNoValueTF{\textlabel{#6}{FD:#3}}{}{\textlabel{#7}{DD:#3} & \cross}}%
        \end{tabularx}%
    \end{mdframed}%
}

%=========================================================================
%                               TEXT LABEL
%=========================================================================
\makeatletter%
% Arguments:
%  1) The text
%  2) The label
\newcommand*{\textlabel}[2]{%
  \edef\@currentlabel{#1}% Set target label
   #1\phantomsection\label{#2}% Print and store label
}
\makeatother



\mdfdefinestyle{whiteBox}{%
    linecolor=black,
    outerlinewidth=0.75pt,
    roundcorner=6pt,
    innertopmargin=10pt,
    innerbottommargin=10pt,
    innerrightmargin=10pt,
    innerleftmargin=10pt,
    backgroundcolor=white,
    outermargin=0cm,
    nobreak=true,
    align=center}

%=========================================================================
%                       Profile image in border
%=========================================================================
\newsavebox\profileImageBox
\NewDocumentCommand{\profileImage}%
      {O{width=0.6\linewidth}
       O{draw=black,line width=0.75pt,rounded corners=6pt}
       m}{%
   \savebox\profileImageBox{\includegraphics[#1]{#3}}%
   \begin{adjustbox}{valign=t}
       \begin{tikzpicture}%
        \draw [path picture={%
                       \node at (path picture bounding box.center) {%
                           \usebox\profileImageBox};},#2]
              (0,0)  rectangle (\wd\profileImageBox,\ht\profileImageBox);
       \end{tikzpicture}%
   \end{adjustbox}%
}

%=========================================================================
%                                 Cross
%=========================================================================
\newcommand{\cross}[1][.7pt]{\ooalign{%
  \rule[1ex]{1ex}{#1}\cr% Horizontal bar
  \hss\rule{#1}{.7em}\hss\cr}% Vertical bar
}

\begin{document}

\section{Carl Wilhelm Larsen}
    \label{CarlWilhelmLarsen1867}

    \createPerson%
        <CarlVilhelmLarsen1867.jpg>%
        [Carl]%
        {CarlWilhelmLarsen1867}%
        {315}%
        [5 maj 1867]%
        <18 maj 1953>%

\end{document}
3
  • Sorry: OMG for this lengthy \IfValueTF stuff. You should really think about a keyvalue interface
    – user31729
    Dec 15, 2015 at 16:38
  • @ChristianHupfer I know, people always say that, but I don't know how to go on with it. Anyway, you don't have to think about it in this case. It is only needed to deside when to print what in the table and how many tows it should have. Therefor, it isn't relevant in this question :)
    – 7heViking
    Dec 15, 2015 at 16:41
  • Ok, you could ask another question then ;-)
    – user31729
    Dec 15, 2015 at 16:53

1 Answer 1

4

Use imakeidx package and its \index[foo] command — this allows for usage of split indexes:

Say \makeindex[name=nameindex,title={Index of persons}] in the preamble, use \index[foo]{your person entry} and \printindex[nameindex] where you want to have it.

I've put hyperref at the end of the package list ;-)

No other comments on the huge \createPerson command.

\documentclass{article}
\usepackage{tikz}
\usepackage{datetime}
\usepackage[danish]{varioref}
\usepackage{xifthen}
\RequirePackage[framemethod=TikZ]{mdframed}
\usepackage{multirow, tabularx}
\usepackage[]{units}
\usepackage{adjustbox}
\usepackage{xparse}
\usepackage{imakeidx}
\usepackage{hyperref}


%=========================================================================
%                             CREATE PERSON NEW
%=========================================================================
%Arguments: 
%   1)  MANDATORY   - Image destination
%   2)  [OPTIONAL]  - Called name
%   3)  MANDATORY   - Reference to the current full name
%   4)  [OPTIONAL]  - Full birth name
%   5)  MANDATORY   - Uniqueue Reference number
%   6)  [OPTIONAL]  - Birth date in the format of dd. mmm. yyyy
%   7)  <OPTIONAL>  - Death date in the format of dd. mmm. yyyy
\NewDocumentCommand\createPerson{r<>omomo+d<>}
{
    \begin{mdframed}[style=whiteBox]%
%        \profileImage[width=0.25\textwidth]{Images/People/ProfileImages/#1}
        \profileImage[width=0.25\textwidth]{#1}%
        \index[nameindex]{#3}
        \begin{tabularx}{0.75\textwidth}[t]{lXrc}%
            % Row one
            Navn:   &   \nameref{#3}    & \textlabel{#5}{PERSON_ID:#3}    & $\Re$%
            %Create new row if needed
            \IfNoValueTF{#2}%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}}%
                        {\\}}%
                    {\\}}%
                {\\}%
            % Row two
            \IfNoValueTF{#4}%
                % If no birth name
                {\IfNoValueTF{#2}%
                    % If no called name
                    {&&}%
                    % If a called name
                    {Kaldenavn: & \textlabel{#2}{KN:#3} &}}%
                %If a birth name
                {Fødenavn: & #4 &}%
                %
                \IfNoValueTF{#6}%
                       % If no birth date
                       {\IfNoValueTF{#7}{}{\textlabel{#7}{DD:#3} & \cross}}%
                       {\textlabel{#6}{FD:#3} & $\star$}%
            % Create new row if needed    
            \IfNoValueTF{#2}%
                {%
                \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                }%
                {\IfNoValueTF{#4}%
                    {\IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {\\}%
                        }%
                    }%
                    {\\}%
                }%
            % Row three
            \IfNoValueTF{#2}%
                % If no called name
                {%
                    \IfNoValueTF{#6}%
                        {}%
                        {\IfNoValueTF{#7}%
                            {}%
                            {&&}%
                        }%
                }%
                % If a called name
                {\IfNoValueTF{#4}%
                    % If no birth name
                    {
                        \IfNoValueTF{#6}%
                            {}%
                            {\IfNoValueTF{#7}%
                                {}%
                                {&&}%
                            }%
                    }%
                    %If birth name
                    {Kaldenavn: & \textlabel{#2}{KN:#3} &}%
                }%
            %
            \IfNoValueTF{#7}%
                       % If no death date
                       {}%
                       {\IfNoValueTF{\textlabel{#6}{FD:#3}}{}{\textlabel{#7}{DD:#3} & \cross}}%
        \end{tabularx}%
    \end{mdframed}%
}

%=========================================================================
%                               TEXT LABEL
%=========================================================================
\makeatletter%
% Arguments:
%  1) The text
%  2) The label
\newcommand*{\textlabel}[2]{%
  \edef\@currentlabel{#1}% Set target label
   #1\phantomsection\label{#2}% Print and store label
}
\makeatother



\mdfdefinestyle{whiteBox}{%
    linecolor=black,
    outerlinewidth=0.75pt,
    roundcorner=6pt,
    innertopmargin=10pt,
    innerbottommargin=10pt,
    innerrightmargin=10pt,
    innerleftmargin=10pt,
    backgroundcolor=white,
    outermargin=0cm,
    nobreak=true,
    align=center}

%=========================================================================
%                       Profile image in border
%=========================================================================
\newsavebox\profileImageBox
\NewDocumentCommand{\profileImage}%
      {O{width=0.6\linewidth}
       O{draw=black,line width=0.75pt,rounded corners=6pt}
       m}{%
   \savebox\profileImageBox{\includegraphics[#1]{#3}}%
   \begin{adjustbox}{valign=t}
       \begin{tikzpicture}%
        \draw [path picture={%
                       \node at (path picture bounding box.center) {%
                           \usebox\profileImageBox};},#2]
              (0,0)  rectangle (\wd\profileImageBox,\ht\profileImageBox);
       \end{tikzpicture}%
   \end{adjustbox}%
}

%=========================================================================
%                                 Cross
%=========================================================================
\newcommand{\cross}[1][.7pt]{\ooalign{%
  \rule[1ex]{1ex}{#1}\cr% Horizontal bar
  \hss\rule{#1}{.7em}\hss\cr}% Vertical bar
}


\makeindex[name={nameindex},title={Index of persons}]
\begin{document}

\section{Carl Wilhelm Larsen}
    \label{CarlWilhelmLarsen1867}

    \createPerson%
        <beeduck.jpg>
%        <CarlVilhelmLarsen1867.jpg>%
        [Carl]%
        {CarlWilhelmLarsen1867}%
        {315}%
        [5 maj 1867]%
        <18 maj 1953>%

\printindex[nameindex]

\end{document}

enter image description here

3
  • Thanks for the quick solution. Just one thing :) I donøt understand how the indexing works. What is it, it searches for when I e.g. write: \index[nameindex]{\nameref{#3}}? And is it possible to attach 2 tags for the same person, so it both gives a hit on the called name and the full name (in the same entry of the index)?
    – 7heViking
    Dec 15, 2015 at 17:09
  • ah got it. I am just setting a mark for the index, when calling \index
    – 7heViking
    Dec 15, 2015 at 17:12
  • @FireFly3000: Ok then ;-)
    – user31729
    Dec 15, 2015 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .