打印内容 .unknown \pgfkeys

打印内容 .unknown \pgfkeys

我有很多信息要写入族谱树中。我想将其中一部分写入族谱树中,其余部分写入下一页,单击人名即可访问。

该树是用包创建的genealogytree,数据存储在单独的文件中测试数据库.tex

我尝试创建一个\newcommand从数据库打印数据但什么都没打印出来。有人能向我解释如何正确地将参数传递给新命令吗?

最终目标是打印所有人的数据,理想情况下无需在新定义的命令中输入每个姓名来打印其数据。

平均能量损失

测试.tex

\documentclass{article}

\usepackage[all]{genealogytree}

\begin{document}
    
    % Define new keys in genealogytree database
    \pgfkeys{/gtr/database/.cd,
        nationality/.store in=\nationality,
        nationality=unknown,
        given name/.store in=\givenname,
        family name/.store in=\familyname,
        language/.store in=\language
    }
    
    % Define new format for genealogytree
    \gtrDeclareDatabaseFormat{xTestFormat}
    {
        % Define box title based on nationality
        \ifdefined\nationality
        \gtrset{box={title=\nationality}}
        \fi
        % Define tcolorbox parameters based on 'nationality' key
        \tcbset{unknown/.style={colback=black!5!white,colframe=black}}
        \tcbset{french/.style={colback=blue!5!white,colframe=blue}}
        \tcbset{british/.style={colback=red!5!white,colframe=red}}  
    }
    { % Define informations to print in the box
        \gtrPrintSex~\textcolor{blue}{\textbf{\givenname}}
        
        \ifdefined\familyname
        \familyname
        \fi
        
        \language
        
        \gtrifcommentdefined{\gtrPrintComment}{}
    }
    
    \input{test_database}
    
    % Create a command to print people complete data
    \newcommand\PrintCompletePeople[1]{
            
        This is the direct output: #1
        
        I want to know what is behind the key:
        
        \pgfkeys{/mydata/.cd,
            nationalitybis/.store in=\nationalitybis,
            nationalitybis=\pgfkeysvalueof{/gtr/database/people/#1/nationality}
        }
    
        \nationalitybis
        
        but nothing is printed
    }
    
    
    \begin{tikzpicture}
        
        \genealogytree[
            timeflow=down,
            processing=database,
            database format=xTestFormat,
            box={\nationality}
        ]
        {child[id=fam_Water]{
            p[id=Justine]{people=JustineID}
            g[id=Tom]{people=TomID}
            c[id=Jane]{people=JaneID}
            }
        }
        
    \end{tikzpicture}

    \newpage
    
    \PrintCompletePeople{JaneID}
    
    
    
\end{document}

测试数据库.tex

% Create database

% Jane Water
\pgfkeys{/gtr/database/.cd,
    people/.is choice,
    people/JaneID/.style={
        female,
        nationality = british,
        given name  = Jane,
        family name = Water,
        language    = {English},
        comment     = {Something else}
    }
}

% Justine Random
\pgfkeys{/gtr/database/.cd,
    people/.is choice,
    people/JustineID/.style={
        female,
        nationality = french,
        given name  = Justine,
        language    = {French, English},
%       family name = Random,
        comment     = {Something interesting}
    }
}

% Tom Water
\pgfkeys{/gtr/database/.cd,
    people/.is choice,
    people/TomID/.style={
        male,
        nationality = british,
        given name  = Tom,
        family name = Water,
        language    = {English},
%       comment     = {There is nothing to say}
    }
}

答案1

我认为对按键的作用存在一些误解。/.is choice处理程序定义了一个选择。因此您需要

\pgfkeys{/gtr/database/.cd,people=#1}%

“执行”样式。然后国籍就会被存储,\nationality因为你在拨号时说过

nationality/.store in=\nationality,

完整示例。

\documentclass{article}
\begin{filecontents}[overwrite]{test_database.tex}
% Create database

% Jane Water
\pgfkeys{/gtr/database/.cd,
    people/.is choice,
    people/JaneID/.style={
        female,
        nationality = british,
        given name  = Jane,
        family name = Water,
        language    = {English},
        comment     = {Something else}
    }
}

% Justine Random
\pgfkeys{/gtr/database/.cd,
    people/.is choice,
    people/JustineID/.style={
        female,
        nationality = french,
        given name  = Justine,
        language    = {French, English},
%       family name = Random,
        comment     = {Something interesting}
    }
}

% Tom Water
\pgfkeys{/gtr/database/.cd,
    people/.is choice,
    people/TomID/.style={
        male,
        nationality = british,
        given name  = Tom,
        family name = Water,
        language    = {English},
%       comment     = {There is nothing to say}
    }
}

\end{filecontents}

\usepackage[all]{genealogytree}

\begin{document}
    
    % Define new keys in genealogytree database
    \pgfkeys{/gtr/database/.cd,
        nationality/.store in=\nationality,
        nationality=unknown,
        given name/.store in=\givenname,
        family name/.store in=\familyname,
        language/.store in=\language
    }
    
    % Define new format for genealogytree
    \gtrDeclareDatabaseFormat{xTestFormat}
    {
        % Define box title based on nationality
        \ifdefined\nationality
        \gtrset{box={title=\nationality}}
        \fi
        % Define tcolorbox parameters based on 'nationality' key
        \tcbset{unknown/.style={colback=black!5!white,colframe=black}}
        \tcbset{french/.style={colback=blue!5!white,colframe=blue}}
        \tcbset{british/.style={colback=red!5!white,colframe=red}}  
    }
    { % Define informations to print in the box
        \gtrPrintSex~\textcolor{blue}{\textbf{\givenname}}
        
        \ifdefined\familyname
        \familyname
        \fi
        
        \language
        
        \gtrifcommentdefined{\gtrPrintComment}{}
    }
    
    \input{test_database}
    
    % Create a command to print people complete data
    \newcommand\PrintCompletePeople[1]{
            
        This is the direct output: #1
        
        I want to know what is behind the key:      
        \pgfkeys{/gtr/database/.cd,people=#1}%
        \nationality
    }
    
    
    \begin{tikzpicture}
        
        \genealogytree[
            timeflow=down,
            processing=database,
            database format=xTestFormat,
            box={\nationality}
        ]
        {child[id=fam_Water]{
            p[id=Justine]{people=JustineID}
            g[id=Tom]{people=TomID}
            c[id=Jane]{people=JaneID}
            }
        }
        
    \end{tikzpicture}

    \newpage
    
    \PrintCompletePeople{JaneID}
    
    
    
\end{document}

在此处输入图片描述

相关内容