LATEX-L Archives

Mailing list for the LaTeX3 project


Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Mailing list for the LaTeX3 project <[log in to unmask]>
Joseph Wright <[log in to unmask]>
Mon, 17 Aug 2009 17:35:53 +0100
text/plain; charset=ISO-8859-1
Mailing list for the LaTeX3 project <[log in to unmask]>
text/plain (90 lines)
Hello all,

First, thanks very much for the engagement with the "xparse" thread.
Lots of useful and illuminating feedback. The next item on the list to
be sorted is the template package/concept. (For those who wonder why the
list is in this order: the output and galley ideas need template,
template needs xparse and xparse needs expl3. So we are working in the
right direction!)

As before, I'd like to start by giving a bit of background and laying
out what template is about.

I struggled to get the idea at all (I'm not sure I have it completely
yet), so I've put together "template-alt" to try to put things into a
form I can understand. As I'll explain in a moment, there are also a few
other reasons I wanted to do my own version.

The idea of template is that it lets you separate out design from code,
and to pre-set various parts of the design so that they do not have to
be evaluated at every use.  I'm still not clear on the
\DeclareTemplateType concept, so I'll go with what I can understand. (If
anyone can show where this extra division is useful, please do tell.)

You start by declaring a template, which is a generalised form for a
design function. For example, you might have a template called
"division" that is a generalised chapter/section. The template has a
number of keys, which will set variables later. The trunk template
implementation uses a modified keyval method for setting these up, but
in my template-alt version I've used the same concept as is now present
in l3keys.  Something like (very simplified, of course):

\DeclareTemplate { division } { 3 } {
  font-name .set:N = \l_division_font_name_tl,
  font-size .set:N = \l_division_font_size_tl,
  % Code, including:
  % to mark where keys are applied.

You'll notice the number: this is used to allow the template to take a
number of arguments.

The next part of the process is to create an "instance". The idea here
is to fix particular parameters of the template with a given name.  So
pursuing the very simple example, we might have one instance for chapters:

\DeclareInstance { chapter } { division } {
  font-name    = Helvetica,
  font-size    = 20 pt,

and so on. The point is that the keys are set "now", so that when we use
the instance there is less to do.

Finally, you need to use an instance. This will probably be inside a
command, with the idea being that you can use the same instance with
different function names. At this stage, the parameters have to be
picked up. So continuing with the example:

\DeclareDocumentCommand \chapter { s o m } {
  \IfNoValueTF {#2} {
    % No short title, so re-use the long one
    \UseInstance { chapter } { division } #1 {#3} {#3}
    % Separate short title
    \UseInstance { chapter } { division } #1 {#2} {#3}

(In a real implementation, the star argument should affect whether the
instance even gets a number for the chapter, I think. But the concept is
hopefully clear-ish.)

At present, there are various bells and whistles to this in template, of
which only some are implemented in template-alt as I don't follow all of
them. So there are various questions:
 - Does this broadly make sense to other people?
 - Does the current interface provide enough flexibility?

I think the idea is actually pretty clever, but the current trunk
template implementation is very hard to read (hence template-alt). Any
ideas/thoughts/feedback welcome.  As the first paragraph of the e-mail
indicates, sorting out how template should work is a key step as some
very major stuff needs to use it.
Joseph Wright