Re: [NTG-context] xml and lua again

2011-10-24 Thread Hans Hagen

On 22-10-2011 18:46, Thomas A. Schmitz wrote:

Hi all,

again, I'm playing a bit with processing my xml in lua. I want a simple
interface for processing tables (I don't need all the power and
complexity of cals tables and want to learn something in the process).
And I thought that collecting the setups in lua might be the easiest
way, but so far, I haven't been successful. Here's an example:

\startbuffer[test]
a
nattable frame=on
tr
td1/td
td2/td
td3/td
td4/td
/tr
tr
td5/td
td6/td
td7/td
td8/td
/tr
/nattable
/a
\stopbuffer

\startxmlsetups xml:testsetups
\xmlsetsetup{main}{a|nattable|tr|td|}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:testsetups}

\startxmlsetups xml:a
\xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:nattable
\startluacode
framestate = lxml.att(#1, frame)
context(framestate)
context(true)
context.placefigure( { here }, none , function()
context.setupTABLE( { frame=on } )
context.bTABLE()
context.xmlflush(#1)
context.eTABLE()
end)
\stopluacode
\stopxmlsetups

\startxmlsetups xml:tr
\startluacode
context.bTR()
context.xmlflush(#1)
context.eTR()
\stopluacode
\stopxmlsetups

\startxmlsetups xml:td
\startluacode
context.bTD()
context.xmlflush(#1)
context.eTD()
\stopluacode
\stopxmlsetups

\starttext
\xmlprocessbuffer{main}{test}{}
\stoptext

question: I have the value on in the lua variable framestate. But
how can I pass this on to the line
context.setupTABLE( { frame=on } )?
I tried something like
context.setupTABLE( { frame= .. framestate } )
but that doesn't work. Any suggestions?


why so complex

\startbuffer[test]
a
  nattable frame=on
tr
  td1/td
  td2/td
  td3/td
  td4/td
/tr
tr
  td5/td
  td6/td
  td7/td
  td8/td
/tr
  /nattable
  nattable frame=off
tr
  td1/td
  td2/td
  td3/td
  td4/td
/tr
tr
  td5/td
  td6/td
  td7/td
  td8/td
/tr
  /nattable
  nattable frame=no
tr
  td1/td
  td2/td
  td3/td
  td4/td
/tr
tr
  td5/td
  td6/td
  td7/td
  td8/td
/tr
  /nattable
/a
\stopbuffer

\startxmlsetups xml:testsetups
\xmlsetsetup{main}{a|nattable|tr|td|}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:testsetups}

\startxmlsetups xml:a
\xmlflush{#1}
\stopxmlsetups

\xmlmapvalue {nattable:frame} {on}  {on}
\xmlmapvalue {nattable:frame} {yes} {on}
\xmlmapvalue {nattable:frame} {off} {off}
\xmlmapvalue {nattable:frame} {no}  {off}

\startxmlsetups xml:nattable
\placefigure
[here,none]
{}
{

\setupTABLE[frame=\xmlval{nattable:frame}{\xmlatt{#1}{frame}}{on}]
\bTABLE
\xmlflush{#1}
\eTABLE
}
\stopxmlsetups

\startxmlsetups xml:tr
\bTR
\xmlflush{#1}
\eTR
\stopxmlsetups

\startxmlsetups xml:td
\bTD
\xmlflush{#1}
\eTD
\stopxmlsetups

\starttext
\xmlprocessbuffer{main}{test}{}
\stoptext

In x-cals.lua / mkiv you can see an example of pure lua solution. It 
boils down to applying a function the the whole table element.


Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing style inside verbatim in XML

2011-10-24 Thread Hans Hagen

On 21-10-2011 22:18, Mojca Miklavec wrote:

Hello,

Is there any simple way to typeset the following example properly in ConTeXt?

I have an example of text that has to obey lines and spaces, but I
would like to apply some color to make it more readable. The
attachment contains an example of HTML which displays fine in my
browser, and it should look similar with ConTeXt.

I have problems with literal typesetting ofspan class=...  (that
should have applied style instead), but maybe I only have wrong
settings in my parser.

When I use \xmlsetfunction{main}{pre}{lxml.displayverbatim}, then I
cannot color the numbers. When I use, according to Wolfgang's
suggestion,

\startxmlsetups pre
\setuplines[style=mono,space=yes]
\startlines
\xmlflush{#1}
\stoplines
\stopxmlsetups

then all the spaces are eaten up by XML parser (or somewhere else), so
that I don't get the desired result. Any ideas about this?

I'm also sending a self-contained example with \setuplines which
doesn't really work in the desired way.


The next beta will provide two extra flushers. The following patch to 
your example seems to work ok then.


\startxmlsetups all:html
\xmlsetsetup{main}{head|h1|pre|span}{*}
\stopxmlsetups

\xmlmapval{span}{n}{\bf\red}

\startxmlsetups span
\start
\xmlval{span}{\xmlatt{#1}{class}}{}
\xmlflush{#1}
\stop
\stopxmlsetups

\startxmlsetups pre
\start \tttf
   %\xmlflush{#1}
   %\xmlflushlinewise{#1}
\xmlflushspacewise{#1}
\stop
\stopxmlsetups

Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] xml and lua again

2011-10-24 Thread Thomas A. Schmitz

On 10/24/2011 12:17 PM, Hans Hagen wrote:

why so complex


Hi Hans,

yes, I'm aware that this procedure is quite silly for this example, this 
was just for myself, for educational purposes. As soon as the setup 
becomes more complex, I thought it might be easier to collect and 
process the options in lua than in tex (as I have done before), but I'm 
running against a wall here (see my exchange with Peter about goat milk 
yesterday). So the real question is: how can I collect data such as an 
attribute value to process it with lua, say in the form


   if lxml.att(t, frame) == on then
  context(Yes, the frame is really on!)
   else
  context(Nope, sorry, it's still off.)
   end

I don't really understand what kind of object a call such as lxml.att(t, 
frame) produces.


All best

Thomas
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] xml and lua again

2011-10-24 Thread Hans Hagen

On 24-10-2011 14:18, Thomas A. Schmitz wrote:

On 10/24/2011 12:17 PM, Hans Hagen wrote:

why so complex


Hi Hans,

yes, I'm aware that this procedure is quite silly for this example, this
was just for myself, for educational purposes. As soon as the setup
becomes more complex, I thought it might be easier to collect and
process the options in lua than in tex (as I have done before), but I'm
running against a wall here (see my exchange with Peter about goat milk
yesterday). So the real question is: how can I collect data such as an
attribute value to process it with lua, say in the form

if lxml.att(t, frame) == on then
context(Yes, the frame is really on!)
else
context(Nope, sorry, it's still off.)
end

I don't really understand what kind of object a call such as lxml.att(t,
frame) produces.


all lxml.* calls print something to tex, so when you're at the lua end 
and want to stay there you should use the xml.* methods; also, when you 
have an element, say e then there is an e.at table that has all 
attributes



-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Links in exported XHTML file

2011-10-24 Thread Hans Hagen

On 21-10-2011 11:27, Andreas Harder wrote:

\setupinteraction[state=start]

\setupbackend[export=yes,xhtml=yes,css=export-example.css]

\starttext
   \useURL[google][http://www.google.com/][][Google] \from[google]
   \textreference[txt:ref]{some text} \in[txt:ref] % OK
   \goto{Google}[url(http://www.google.com/)]
\stoptext


in next beta

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Image compression/resizing in PDFs

2011-10-24 Thread Hans Hagen

On 21-10-2011 11:54, John Devereux wrote:


Hi all,

Is there a way to have context automatically compress or resample
included images to a given output resolution? I have not been following
recent developments...

I can obviously pre-reduce all images to the desired dpi. But:

1) This is a bit of work (and hard to get non-technical people to do)

2) In 5 years time we might want the images to be higher resolution and
not be as concerned about PDF size. But the information will be lost (or
be elsewhere).

So a command line or document setting would be ideal, is there such a
thing? \setpdfimageresolution[300dpi].


You can plug in a converter:

\startluacode

figures.converters[png] = {
[lowres.png] = function(oldname,newname,resolution)
os.execute(string.format('gm convert -depth 1 %s 
%s',oldname,newname))

end,
}

-- the following is automatic in next beta

figures.suffixes[lowres.png] = figures.suffixes.png

\stopluacode

And then use:

\starttext
\externalfigure[mill.png][conversion=lowres.png]
\stoptext

downsamples images are cached so the overhead is minimal

Hans



-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Image compression/resizing in PDFs

2011-10-24 Thread Aditya Mahajan

downsamples images are cached so the overhead is minimal


Is caching based only on the figure name? If I change the original figure, 
will the cached figure be updated?


Aditya
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] Image compression/resizing in PDFs

2011-10-24 Thread Hans Hagen

On 24-10-2011 16:29, Aditya Mahajan wrote:

downsamples images are cached so the overhead is minimal


Is caching based only on the figure name? If I change the original
figure, will the cached figure be updated?


Sure,

local oldtime = 
lfs.attributes(oldname,'modification') or 0
local newtime = 
lfs.attributes(newname,'modification') or 0

if newtime == 0 or oldtime  newtime then

In fact it's just integration of old resource library code (ruby stuff 
that happened between runs).


Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] Anand Raj wants to chat

2011-10-24 Thread Anand Raj
---

Anand Raj wants to stay in better touch using some of Google's coolest new
products.

If you already have Gmail or Google Talk, visit:
http://mail.google.com/mail/b-709fcd6ca7-7faa394ef6-zj888FertlMzrmOH2voj9oglvSs
You'll need to click this link to be able to chat with Anand Raj.

To get Gmail - a free email account from Google with over 2,800 megabytes of
storage - and chat with Anand Raj, visit:
http://mail.google.com/mail/a-709fcd6ca7-7faa394ef6-zj888FertlMzrmOH2voj9oglvSs

Gmail offers:
- Instant messaging right inside Gmail
- Powerful spam protection
- Built-in search for finding your messages and a helpful way of organizing
  emails into conversations
- No pop-up ads or untargeted banners - just text ads and related information
  that are relevant to the content of your messages

All this, and its yours for free. But wait, there's more! By opening a Gmail
account, you also get access to Google Talk, Google's instant messaging
service:

http://www.google.com/talk/

Google Talk offers:
- Web-based chat that you can use anywhere, without a download
- A contact list that's synchronized with your Gmail account
- Free, high quality PC-to-PC voice calls when you download the Google Talk
  client

We're working hard to add new features and make improvements, so we might also
ask for your comments and suggestions periodically. We appreciate your help in
making our products even better!

Thanks,
The Google Team

To learn more about Gmail and Google Talk, visit:
http://mail.google.com/mail/help/about.html
http://www.google.com/talk/about.html

(If clicking the URLs in this message does not work, copy and paste them into
the address bar of your browser).
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] xml and lua again

2011-10-24 Thread Thomas A. Schmitz

On 10/24/2011 02:26 PM, Hans Hagen wrote:

if lxml.att(t, frame) == on then
context(Yes, the frame is really on!)
else
context(Nope, sorry, it's still off.)
end

I don't really understand what kind of object a call such as lxml.att(t,
frame) produces.


all lxml.* calls print something to tex, so when you're at the lua end
and want to stay there you should use the xml.* methods; also, when you
have an element, say e then there is an e.at table that has all attributes


OK, excuse me for being particularly thick today: there doesn't seem to 
be xml.att, only xml.attribute, so it should be something like:


function tableinit(t)
   if xml.attribute(t, /, frame, off) == on then
  context(Yes, the framestate is really on!)
   else
  context(Nope, sorry, it's still off.)
   end
end

(if I understand the definition of xml.attribute correctly: 
id,pattern,a,default)?


Thomas
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] How do I test for empty labeltext?

2011-10-24 Thread Mojca Miklavec
Hello,

The following code

\setuplabeltext[test=]
test is \doifemptyelse{\labeltext{test}}{empty}{not empty}

doesn't work as intended for the reasons that I approximately
understand (not exactly, but I understand that there might be a lot of
weird stuff returned when I ask for labeltext). However I have no idea
how to check if text is empty or not.

As an exception :) :) :), MKIV hints should be highly appreciated and
enough for this particular application.

Mojca


PS: the extended example looks approximately as follows:

\def\document#1#2{
\setuplabeltext[name={{#1}},company={{#2}}]
\startstandardmakeup
\setups{content}
\setups{decoration}
\stopstandardmakeup
}

\startsetups content
This is for \labeltext{name}%
\doifemptyelse{\labeltext{company}}{.}{, working for \labeltext{company}.}
\stopsetups

I have no problem changing the complete code and I can already find a
workaround by defining some new if inside definition of \document,
but I'm still slightly curious to know how to test for existence of a
label. The sources contain
definelabels(setuplabeltext, data.texts, true)
and it is not too clear to me how to decrypt the rest with too much pain.
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] How do I test for empty labeltext?

2011-10-24 Thread Hans Hagen

On 24-10-2011 19:41, Mojca Miklavec wrote:

Hello,

The following code

\setuplabeltext[test=]
test is \doifemptyelse{\labeltext{test}}{empty}{not empty}

doesn't work as intended for the reasons that I approximately
understand (not exactly, but I understand that there might be a lot of
weird stuff returned when I ask for labeltext). However I have no idea
how to check if text is empty or not.

As an exception :) :) :), MKIV hints should be highly appreciated and
enough for this particular application.


an empty test is always somewhat special as there can be an unexpandable 
macro inside that eventually expands to nothing


you can try \doiftextelse instead

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] xml and lua again

2011-10-24 Thread Hans Hagen

On 24-10-2011 19:00, Thomas A. Schmitz wrote:

On 10/24/2011 02:26 PM, Hans Hagen wrote:

if lxml.att(t, frame) == on then
context(Yes, the frame is really on!)
else
context(Nope, sorry, it's still off.)
end

I don't really understand what kind of object a call such as lxml.att(t,
frame) produces.


all lxml.* calls print something to tex, so when you're at the lua end
and want to stay there you should use the xml.* methods; also, when you
have an element, say e then there is an e.at table that has all
attributes


OK, excuse me for being particularly thick today: there doesn't seem to
be xml.att, only xml.attribute, so it should be something like:

function tableinit(t)
if xml.attribute(t, /, frame, off) == on then
context(Yes, the framestate is really on!)
else
context(Nope, sorry, it's still off.)
end
end

(if I understand the definition of xml.attribute correctly:
id,pattern,a,default)?


sure, oryou can play with

if xml.filter(t,.[@frame=on]) then

the x-*.lua show some tricks


Hans



-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] Question about chapter headings

2011-10-24 Thread Alasdair McAndrew
I'm trying to set up a chapter heading which looks like this:

Chapter 4

This is the fourth chapter

That is, there are two lines, one of which says Chapter followed by its
number, and the next which is the chapter title.  What is the easiest way to
do this?  I've tried

\def\chap#1#2{Chapter #1\crlf #2}

\setuphead[chapter][
   command=\chap,
   style=bfc,
   after={\blank[1cm]},
]

But this doesn't work (and nor do many other variations in the chap
command).  I'm a bit stymied here - and I'd welcome some advice.

Thanks,
Alasdair
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___