ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: Fabrice Couvreur <fabrice1.couvreur@gmail.com>
To: mailing list for ConTeXt users <ntg-context@ntg.nl>
Subject: Re: Color a column (xtable, lua)
Date: Sun, 27 Jan 2019 00:59:11 +0100	[thread overview]
Message-ID: <CACyK-eovnwZBJzpt_QXzdpJOg+Mk9p9b69Dv9Lx6ex68oKzTRw@mail.gmail.com> (raw)
In-Reply-To: <916e07d8-1988-f18e-e53b-d2f99abb6184@gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 5547 bytes --]

Hi Henry,
Thank you for your proposition. I tested both : the first work  but not the
second.
Fabrice

lua error       > lua error on line 13 in file /home/viserion/Ntg_7.tex:

...ext/tex/texmf-context/tex/context/base/mkiv/tabl-xtb.lua:1269: attempt
to index a nil value (upvalue 'data')

 3
 4     \startuseMPgraphic{tablebackground}{i,j}
 5     if (\MPvar{i} = 1) or (\MPvar{j} = 1):
 6           fill OverlayBox withcolor \MPcolor{fondpaille} ;
 7     fi;
 8     \stopuseMPgraphic
 9
10     \defineoverlay
11       [tablebackground]
12
13 >>
[\useMPgraphic{tablebackground}{i=\currentxtablerow,j=\currentxtablecolumn}]
14
15     \setupxtable[background=tablebackground]
16
17     \starttext
18     \startluacode
19     local letters_1 = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J"
}
20     local letters_2 = { "A", "0", "1", "1", "0", "", "", "", "", "" }
21     context.startxtable({"align={middle,lohi},
width=1.25cm,offset=0.8ex"})
22
23     context.startxrow()


?

Le dim. 27 janv. 2019 à 00:34, Henri Menke <henrimenke@gmail.com> a écrit :

> On 1/27/19 12:26 PM, Henri Menke wrote:
> > On 1/27/19 12:08 PM, Fabrice Couvreur wrote:
> >> Hi,
> >> How to color the first column as I did for the first line ?
> >
> > Stolen from Wolfgang's answer on TeX.SX.
> > https://tex.stackexchange.com/a/464771
> >
>
> You could also evaluate the conditional purely in MetaPost.  I don't
> know if that would be faster, but it's a bit more readable to me.
>
>
> \startuseMPgraphic{tablebackground}{i,j}
> if (\MPvar{i} = 1) or (\MPvar{j} = 1):
>       fill OverlayBox withcolor \MPcolor{fondpaille} ;
> fi;
> \stopuseMPgraphic
>
> \defineoverlay
>   [tablebackground]
>
>
> [\useMPgraphic{tablebackground}{i=\currentxtablerow,j=\currentxtablecolumn}]
>
> \setupxtable[background=tablebackground]
>
> >
> > \definecolor[fondpaille][c=0,m=0,y=0.2,k=0]
> >
> > \startuseMPgraphic {tablebackground}
> >   fill OverlayBox withcolor \MPcolor{fondpaille} ;
> > \stopuseMPgraphic
> >
> > \defineoverlay
> >   [tablebackground]
> >   [\ifnum\currentxtablerow=1
> >        \useMPgraphic{tablebackground}%
> >    \else\ifnum\currentxtablecolumn=1
> >        \useMPgraphic{tablebackground}%
> >    \fi\fi]
> >
> > \setupxtable[background=tablebackground]
> >
> > \starttext
> > \startluacode
> > local letters_1 = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }
> > local letters_2 = { "A", "0", "1", "1", "0", "", "", "", "", "" }
> > context.startxtable({"align={middle,lohi}, width=1.25cm,offset=0.8ex"})
> >
> > context.startxrow()
> > context.startxcell({"background=color,backgroundcolor=white,frame=off"})
> > context("")
> > context.stopxcell()
> > for _, letter in ipairs(letters_1) do
> >     context.startxcell()
> >     context(letter) context.stopxcell()
> > end
> > context.stopxrow()
> >
> > context.startxrow()
> > for _, letter in ipairs(letters_2) do
> >     context.startxcell() context(letter) context.stopxcell()
> > end
> > context.stopxrow()
> >
> > for i=2,10 do
> >     context.startxrow()
> >     context.startxcell()  context(converters.convert("A",i))
> >     context.stopxcell()
> >     context.stopxrow()
> > end
> >
> > context.stopxtable()
> > \stopluacode
> > \stoptext
> >
> >
> >> Thank you
> >> Fabrice
> >>
> >> \definecolor[fondpaille][c=0,m=0,y=0.2,k=0]
> >> \starttext
> >> \startluacode
> >> local letters_1 = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }
> >> local letters_2 = { "A", "0", "1", "1", "0", "", "", "", "", "" }
> >> context.startxtable({"align={middle,lohi}, width=1.25cm,offset=0.8ex"})
> >> context.startxrow()
> >> context.startxcell({"background=color,backgroundcolor=white,frame=off"})
> >> context("") context.stopxcell()
> >> for _, letter in ipairs(letters_1) do
> >>      context.startxcell({"background=color,backgroundcolor=fondpaille"})
> >> context(letter) context.stopxcell()
> >> end
> >> context.stopxrow()
> >> context.startxrow()
> >> for _, letter in ipairs(letters_2) do
> >>      context.startxcell() context(letter) context.stopxcell()
> >> end
> >> context.stopxrow()
> >> for i=2,10 do
> >>      context.startxrow()
> >>      context.startxcell()  context(converters.convert("A",i))
> >> context.stopxcell()
> >>      context.stopxrow()
> >> end
> >> context.stopxtable()
> >> \stopluacode
> >> \stoptext
> >>
> >>
> >>
> ___________________________________________________________________________________
> >> If your question is of interest to others as well, please add an entry
> to the Wiki!
> >>
> >> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> >> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> >> archive  : https://bitbucket.org/phg/context-mirror/commits/
> >> wiki     : http://contextgarden.net
> >>
> ___________________________________________________________________________________
> >>
> >
>
>
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to
> the Wiki!
>
> maillist : ntg-context@ntg.nl /
> http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
>
> ___________________________________________________________________________________

[-- Attachment #1.2: Type: text/html, Size: 9075 bytes --]

[-- Attachment #2: Type: text/plain, Size: 492 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

  reply	other threads:[~2019-01-26 23:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-26 23:08 Fabrice Couvreur
2019-01-26 23:26 ` Henri Menke
2019-01-26 23:33   ` Henri Menke
2019-01-26 23:59     ` Fabrice Couvreur [this message]
2019-01-27  9:23       ` Wolfgang Schuster

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CACyK-eovnwZBJzpt_QXzdpJOg+Mk9p9b69Dv9Lx6ex68oKzTRw@mail.gmail.com \
    --to=fabrice1.couvreur@gmail.com \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).