我如何将一个人的信息与家谱树一起捆绑在宏中

我如何将一个人的信息与家谱树一起捆绑在宏中

我想将每个人的姓名和其他信息封装在一个宏中,然后在家谱树中使用该宏。这是为了减少树本身的混乱,以便于阅读和编辑。但我的尝试都没有成功。

梅威瑟:

\documentclass[varwidth,margin=10pt]{standalone}
\usepackage[all]{genealogytree}

\gtrset{mytree/.style={
    template=database traditional,
    database format=medium no marriage,
  }
}

\newcommand\nSon{name=Son, comment=Prince of the Valley}    % this does not work
%\newcommand\nSon{{name=Son, comment=Prince of the Valley}} % also does not work
%\edef\nSon{name=Son, comment=Prince of the Valley}         % also does not work
%\edef\nSon{{name=Son, comment=Prince of the Valley}}       % also does not work

\begin{document}
\begin{tikzpicture}
  \genealogytree[mytree]{
    parent{
      %g{name=Son, comment=Prince of the Valley} % this works
      g{\nSon}                                   % this does not work
      p{name=Father, comment=King of the Hill}
    }
  }
\end{tikzpicture}
\end{document}

答案1

方法 1:

除非包提供了预先扩展的方法\nSon,否则您必须使用一堆\expandafters 手动完成此操作。

\documentclass[varwidth,margin=10pt]{standalone}
\usepackage[all]{genealogytree}

\gtrset{mytree/.style={
    template=database traditional,
    database format=medium no marriage,
  }
}

\newcommand\nSon{name=Son, comment=Prince of the Valley}
\begin{document}
\begin{tikzpicture}
\def\tmpA{\genealogytree[mytree]}
\def\tmpB{parent}
\expandafter\expandafter\expandafter\tmpA
\expandafter\expandafter\expandafter{%
\expandafter\tmpB
\expandafter{%
\expandafter g%
\expandafter{%
\nSon}       %
      p{name=Father, comment=King of the Hill}
    }
  }
\end{tikzpicture}
\end{document}

在此处输入图片描述

方法 2:

使用\expanded,此处显示几个宏插入:

\documentclass[varwidth,margin=10pt]{standalone}
\usepackage[all]{genealogytree}

\gtrset{mytree/.style={
    template=database traditional,
    database format=medium no marriage,
  }
}

\newcommand\nSon{name=Son, comment=Prince of the Valley}
\newcommand\nPar{name=Father, comment=King of the Hill}
\begin{document}
\begin{tikzpicture}
\def\tmpA{\genealogytree[mytree]}
\expandafter\tmpA\expandafter{\expanded{%
  parent{%
     g{\nSon}       
     p{\nPar}
    }
  }}
\end{tikzpicture}
\end{document}

相关内容