1

I came across a problem in xtemplate with using \KeyValue for keys of type instance. Instance key-types haven't been documented yet, so I could just be doing it wrong.
Here's the smallest example I could come up with:

\documentclass{article}
\usepackage{expl3}
\usepackage{xtemplate}
\ExplSyntaxOn

\DeclareObjectType { format } {1}
\DeclareObjectType { tagged } {2}

\DeclareTemplateInterface { format } { format-text } {1}
  {
    font : tokenlist = \normalfont ,
  }
\DeclareTemplateInterface { tagged } { tagged-text } {2}
  {
    main : instance { format } = normal ,
    tag  : instance { format } = \KeyValue { main } ,
  }

\tl_new:N \l__mwe_tl
\DeclareTemplateCode { format } { format-text } {1}
  { font = \l__mwe_tl , }
  {
    \AssignTemplateKeys
    { \l__mwe_tl #1 }
  }
\DeclareTemplateCode { tagged } { tagged-text } {2}
  {
    main = \__mwe_main:n ,
    tag  = \__mwe_tag:n ,
  }
  {
    \AssignTemplateKeys
    \__mwe_tag:n {#1} \__mwe_main:n {#2}
  }

\DeclareInstance  { format } { normal } { format-text }
  {}
\DeclareInstance  { tagged } { specific } { tagged-text }
  {
    main = normal ,
    tag  = normal ,
  }
\DeclareInstance  { tagged } { default } { tagged-text }
  {
    main = normal ,
  }
\ExplSyntaxOff
\begin{document}

\UseInstance {tagged} {specific} {Y:~} {This one works.}

\UseInstance {tagged} {default} {N:~} {This one fails.}

\end{document}

(the bug report at https://github.com/latex3/latex3/issues/131 suggested trying it a second time, but that didn't work either).

The relevant bits of the log file:

This is pdfTeX, Version 3.14159265-2.6-1.40.20 (MiKTeX 2.9.7200 64-bit) 
Package: expl3 2019-10-02 L3 programming layer (loader) 
Package: xtemplate 2019-05-28 L3 Experimental prototype document functions

! Package xtemplate Error: The instance '\KeyValue {main}' of type 'format' is
(xtemplate)                unknown.
For immediate help type H <return>.
 ...                                              
l.61 ...{tagged} {default} {N:~} {This one fails.}

Does anyone know how to make \KeyValue evaluate earlier?

Your Answer

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

Browse other questions tagged or ask your own question.