[XeTeX] Automate table creation
Khaled Hosny
khaledhosny at eglug.org
Fri Mar 2 11:36:08 CET 2012
On Fri, Mar 02, 2012 at 02:53:49AM -0500, Bruno Le Floch wrote:
> > I tried runing your code, but I get the following message:
> >
> > ! Missing number, treated as zero.
> > <to be read again>
> > *
> > l.20 \maketable{c,0}{1,2}
>
> I knew I should've tested that code.
>
> \documentclass{article}
> \usepackage{xparse}
> \usepackage{array}
> \ExplSyntaxOn
> \DeclareDocumentCommand{\maketable}{mm}
> {
> \exp_args:Nnx \begin{tabular}{c*{\clist_length:n{#2}}c}
> \clist_map_inline:nn {#2} { & \typeset_two:n {##1} }
> \clist_map_inline:nn {#1}
> {
> \\
> \typeset_one:n {##1}
> \clist_map_inline:nn {#2}
> { & \typeset_both:nn {##1} {####1} }
> }
> \end{tabular}
> }
> \cs_new_protected:Npn \typeset_one:n #1 { [#1] }
> \cs_new_protected:Npn \typeset_two:n #1 { (#1) }
> \cs_new_protected:Npn \typeset_both:nn #1#2 {#1#2}
> \ExplSyntaxOff
> \begin{document}
> \maketable{0,1}{a,b,c}
> \end{document}
>
> works. The previous code was mostly missing \usepackage{array} for the
> "*{<number>}c" construction, and had a bunch of other bugs. To
> customize that, change the definition of the three functions
> \typeset_one:n, \typeset_two:n and \typeset_both:n.
>
> Building diacritics from the base accent and the character seems a bit
> tougher than I thought. Others on this thread will know how to do
> that.
With Unicode/OpenType, one should use a combining accent not a spacing
one, and it has to follow it is base. I modified your code a tiny bit,
and using a font with good mark placement and everything is fine:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Gentium Basic}
\usepackage{xparse}
\usepackage{array}
\ExplSyntaxOn
\DeclareDocumentCommand{\maketable}{mm}
{
\exp_args:Nnx \begin{tabular}{c*{\clist_length:n{#2}}c}
\clist_map_inline:nn {#2} { & \typeset_two:n {##1} }
\clist_map_inline:nn {#1}
{
\\
\typeset_one:n {##1}
\clist_map_inline:nn {#2}
{ & \typeset_both:nn {##1} {####1} }
}
\end{tabular}
}
\cs_new_protected:Npn \typeset_one:n #1 { [#1] }
\cs_new_protected:Npn \typeset_two:n #1 { \char"25CC#1 } % use dotted circle as base
\cs_new_protected:Npn \typeset_both:nn #1#2 {#1#2}
\ExplSyntaxOff
\begin{document}
\maketable{a,b,c}{^^^^0302,\char"0303}
\end{document}
Regards,
Khaled
More information about the XeTeX
mailing list