Erro ao carregar uma imagem nomeada por uma ltxkey

Erro ao carregar uma imagem nomeada por uma ltxkey

Sou novo no TeX e no LaTeX e meu primeiro projeto é muito ambicioso. O plano é usar ltxkeyspara definir entradas de banco de dados para o jogo D&D Role Playing e, em seguida, ter modelos LaTeX para imprimir fichas de personagens, estatísticas de monstros, etc. problemas com este arquivo de teste:

\documentclass[letterpaper,landscape]{article}
\pagestyle{empty}
\usepackage[T1]{fontenc}%Use a modern font encoding
\usepackage[sfdefault]{noto}
\usepackage[margin=.5in,nohead,nofoot]{geometry}
\usepackage{graphbox}% Loads graphicx automagically.
\usepackage{anyfontsize}
\usepackage{textpos}
\usepackage[tracingkeys]{ltxkeys}

\setlength{\TPHorizModule}{1in}
\setlength{\TPVertModule}{1in}

\makeatletter  
% Monster Tent Graphic is 300 DPI with:
% * image size of (600x2250 pixels) 2in x 7.5in
% * monster title of 630x62 pixels (2.1in x .207in)
% Use a Data Key: \DnD{WUMPUS}{image}
\newcommand{\DnD}[2]
  {%
    {%
      \def\c{#1}
      \def\v{#2}
      \def\t {\csname DnD@KeyFam@\c \endcsname}%
      \csname cmd\t @\c @\v \endcsname%
    }%
  }

% Define a Creature Data Key:
% \DnDNewCreature{WUMPUS}{title="Grand Wumpus", image=..."}
\newcommand{\DnD@NewCreature}[2]%
  {%
    \ltxkeys@declarekeys[DnD@Creature]{#1}%
      { cmd/\needvalue{title}//;
        cmd/\needvalue{image}//;
      }%
    \expandafter\def\csname DnD@KeyFam@#1\endcsname{DnD@Creature}%
    \ltxkeys@setkeys[DnD@Creature]{#1}{#2}%
  }

\def\gimg {img/MM167-Goblin-BW.png}
\DnD@NewCreature{GoblinBoss}{title=Goblin Boss,image=img/MM167-Goblin-BW.png}

\begin{document}%
\def\m {GoblinBoss}%
\begin{figure}[t]%
  \begin{minipage}{.25\textwidth}%
    % \includegraphics[smash=cc,width=2in,totalheight=2.5in,keepaspectratio,angle=180,hshift=-1.25in,vshift=-2.1in]{\DnD{GoblinBoss}{image}}
    \includegraphics[smash=cc,width=2in,totalheight=2.5in,keepaspectratio,angle=180,hshift=-1.25in,vshift=-2.1in]{img/MM167-Goblin-BW.png}%
    \includegraphics[smash=cr,totalheight=7.5in,width=2.5in]{img/Monster-Tent.png}%
    \begin{textblock}{2.1}(.2,-.42)%
      \rotatebox[origin=c]{180}
        {\centerline{\fontsize{16}{16}\textbf{\DnD{GoblinBoss}{title}}}}  
    \end{textblock}
  \end{minipage}%
\end{figure}
\end{document}
\makeatother

Da forma como está, o arquivo renderiza corretamente a imagem da tenda do monstro e posiciona corretamente a imagem e o título desejados; no entanto, isso ocorre apenas porque o \includegraphicscomando usa o texto literal do caminho para o arquivo a ser carregado, em vez de retirá-lo de um arquivo ltxkey. Se o primeiro comando comentado \includegraphicsfor usado em vez do segundo, recebo um erro obscuro de dentro do includegraphics informando que existe um arquivo "Illegal parameter number in definition of \filename@base".

Se, em vez de ltxkey, eu usar \gimgo que é definido apenas como o caminho do arquivo de imagem, ele funciona. Se eu tentar definir \gimga {\DnD{GoblinBoss}{image}}inserção do código aqui, ele falhará novamente. Se eu apenas imprimir o valor \DnD{GoblinBoss}{image}parece correto. Qualquer ajuda seria apreciada.

Responder1

Você precisa definir o comando de forma que ele se expanda para o nome do arquivo da imagem.

\documentclass[letterpaper,landscape]{article}
\pagestyle{empty}
\usepackage[T1]{fontenc}%Use a modern font encoding
\usepackage[sfdefault]{noto}
\usepackage[margin=.5in,nohead,nofoot]{geometry}
\usepackage{graphbox}% Loads graphicx automagically.
\usepackage{anyfontsize}
\usepackage{textpos}
\usepackage[tracingkeys]{ltxkeys}

\setlength{\TPHorizModule}{1in}
\setlength{\TPVertModule}{1in}

\makeatletter  
% Monster Tent Graphic is 300 DPI with:
% * image size of (600x2250 pixels) 2in x 7.5in
% * monster title of 630x62 pixels (2.1in x .207in)
% Use a Data Key: \DnD{WUMPUS}{image}
\newcommand{\badDnD}[2]
  {%
    {%non expandable group start
      \def\c{#1} % non expandable assignment and space token
      \def\v{#2} % non expandable assignment and space token
      \def\t {\csname DnD@KeyFam@\c \endcsname}% non expandable assignment
      \csname cmd\t @\c @\v \endcsname%
    }%non expandable group end
  }
\newcommand{\DnD}[2]{\csname cmd\csname DnD@KeyFam@#1\endcsname @#1@#2\endcsname}

% Define a Creature Data Key:
% \DnDNewCreature{WUMPUS}{title="Grand Wumpus", image=..."}
\newcommand{\DnD@NewCreature}[2]%
  {%
    \ltxkeys@declarekeys[DnD@Creature]{#1}%
      { cmd/\needvalue{title}//;
        cmd/\needvalue{image}//;
      }%
    \expandafter\def\csname DnD@KeyFam@#1\endcsname{DnD@Creature}%
    \ltxkeys@setkeys[DnD@Creature]{#1}{#2}%
  }

\def\gimg {img/MM167-Goblin-BW.png}
\DnD@NewCreature{GoblinBoss}{title=Goblin Boss,image=example-image.png}

\begin{document}%
\def\m {GoblinBoss}%
\begin{figure}[t]%
  \begin{minipage}{.25\textwidth}%
     \includegraphics[smash=cc,width=2in,totalheight=2.5in,keepaspectratio,angle=180,hshift=-1.25in,vshift=-2.1in]{\DnD{GoblinBoss}{image}}
    \includegraphics[smash=cc,width=2in,totalheight=2.5in,keepaspectratio,angle=180,hshift=-1.25in,vshift=-2.1in]{example-image-a.png}%
    \includegraphics[smash=cr,totalheight=7.5in,width=2.5in]{example-image-b.png}%
    \begin{textblock}{2.1}(.2,-.42)%
      \rotatebox[origin=c]{180}
        {\centerline{\fontsize{16}{16}\textbf{\DnD{GoblinBoss}{title}}}}  
    \end{textblock}
  \end{minipage}%
\end{figure}
\end{document}
\makeatother this is never executed

insira a descrição da imagem aqui

informação relacionada