[NTG-context] Re: PDF, runner, and TikZ patches

2024-03-14 Thread Aditya Mahajan
On Thu, 14 Mar 2024, Jim wrote:

> Max (et al),
> 
> were you hoping the ConTeXt distribution would ship its own
> pgfutil-context.def, or were you hoping that someone could convince Henri
> to put the RGB change in?

We can patch some of the definitions of pgfutil-context.def in m-tikz if really 
needed, but it would be preferable to first check if tikz maintainers are 
willing to merge them upstream. 

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

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net
___


[NTG-context] Re: PDF, runner, and TikZ patches

2024-03-14 Thread Jim
Max (et al),

were you hoping the ConTeXt distribution would ship its own
pgfutil-context.def, or were you hoping that someone could convince Henri
to put the RGB change in?

And, if anyone has the will to push this (or add it in to a ConTeXt
distribution version), I'd still like the cmyk support, even if there is no
ability to specify colour profiles:

\def\pgfutil@emu@cmyk#1#2,#3,#4,#5\@nil
{
\pgfmathsetmacro{\@red@}{(1 - #2) * (1 - #5)}%
\pgfmathsetmacro{\@green@}{(1 - #3) * (1 - #5)}%
\pgfmathsetmacro{\@blue@}{(1 - #4) * (1 - #5)}% 
\expandafter\edef\csname\string\color@#1\endcsname
{\noexpand\xcolor@ {}{}{rgb}{\@red@,\@green@,\@blue@}}
}

I don't see that it would hurt anything, even if it doesn't give complete
cmyk support.

Cheers.
Jim

On Thu, Mar 14, 2024 at 17:18 (-0600), Max Chernoff wrote:

> Hi all,

> I've had a few patches applied to my installation for a little while
> now, so I figured that I should send them in. There's a diff at the end
> of the email, and the modified files are attached [but rejected by the
> mailing list, so sent separately to Hans]

>  * In the definition of "featurecreep()" in "lpdf-mis.lmt",
>"structures.pages.tobesaved[i].status" should be "[...].state" to
> match the definition of "pages.save" in "strc-pag.lua". 

>  * For the "resultof" runner in "util-sbx.lmt", the current io.popen
> mode only works with Windows. See the definition of "l_checkmodep" in
>"liolib.c".

>  * Some of the pgfplots 3D shaders appear to be broken,
> see https://tex.stackexchange.com/a/708121 .

>  * The TikZ "RGB" colour model does not currently work properly. This is
> internally used by "\usepgfplotslibrary[colorbrewer]" among others.
> See https://github.com/pgf-tikz/pgf/pull/1130 .

> Thanks,
> -- Max


> diff --git a/tex/generic/pgf/utilities/pgfutil-context.def 
> b/tex/generic/pgf/utilities/pgfutil-context.def
> index eddab09ab..66edb0980 100644
> --- a/tex/generic/pgf/utilities/pgfutil-context.def
> +++ b/tex/generic/pgf/utilities/pgfutil-context.def
> @@ -26,8 +26,17 @@
>  \def\pgfutil@definecolor#1#2#3{\csname pgfutil@emu@#2\endcsname{#1}#3\@nil}

>  
> \def\pgfutil@emu@rgb#1#2,#3,#4\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{rgb}{#2,#3,#4}}}
> -\def\pgfutil@emu@gray#1#2\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{rgb}{#2,#2,#2}}}
> +\def\pgfutil@emu@gray#1#2\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{gray}{#2}}}
>  
> \def\pgfutil@emu@cmyk#1#2,#3,#4,#5\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{cmyk}{#2,#3,#4,#5}}}
> +\def\pgfutil@emu@RGB#1#2,#3,#4\@nil{%
> +\begingroup
> +\pgfmathdivide@{#2}{255}\let\pgfutil@emu@RGB@r\pgfmathresult
> +\pgfmathdivide@{#3}{255}\let\pgfutil@emu@RGB@g\pgfmathresult
> +\pgfmathdivide@{#4}{255}\let\pgfutil@emu@RGB@b\pgfmathresult
> +
> \edef\pgf@marshal{\def\expandafter\noexpand\csname\string\color@#1\endcsname{%
> +
> \noexpand\xcolor@{}{}{rgb}{\pgfutil@emu@RGB@r,\pgfutil@emu@RGB@g,\pgfutil@emu@RGB@b}}}%
> +\expandafter\endgroup\pgf@marshal
> +}


>  % no need for x colors (users can load it if needed)
> diff --git a/tex/generic/pgfplots/pgfplotsmeshplothandler.code.tex 
> b/tex/generic/pgfplots/pgfplotsmeshplothandler.code.tex
> index 60d6274..106c490 100644
> --- a/tex/generic/pgfplots/pgfplotsmeshplothandler.code.tex
> +++ b/tex/generic/pgfplots/pgfplotsmeshplothandler.code.tex
> @@ -2804,6 +2804,9 @@
>  \def\pgfplotsretval{4}%
>  \fi
>  \fi
> + \if0\pgfplotsretval
> + \def\pgfplotsretval{5}
> + \fi
>  \pgfkeyslet{/pgfplots/surf shading/shading type}\pgfplotsretval%
>  %
>  \pgfplotsplothandlermesh@set@shader@colormap
> diff --git 
> a/tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-luatex.def 
> b/tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-luatex.def
> index 0046daa..b563732 100644
> --- 
> a/tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-luatex.def
> +++ 
> b/tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-luatex.def
> @@ -61,7 +61,7 @@
>  \pgfplotslibrarysurfusepath
>  \endpgfpicture
>  }%
> - \immediate\saveboxresource resources{
> + \saveboxresource resources{
>  /Pattern << \pgfplots@glob@TMPa >> % write the pattern resource dictionary
>  }\pgfutil@tempboxa
>  \leavevmode
> diff --git a/tex/context/base/mkxl/util-sbx.lmt 
> b/tex/context/base/mkxl/util-sbx.lmt
> index b48d4a9..0ee8a16 100644
> --- a/tex/context/base/mkxl/util-sbx.lmt
> +++ b/tex/context/base/mkxl/util-sbx.lmt
> @@ -393,7 +393,7 @@ local runners = {
> if trace then
> report("resultof: %s",command)
> end
> -local handle = iopopen(command,"rb") -- already has flush
> +local handle = iopopen(command,"r") -- already has flush
> if handle then
> local result = handle:read("*all") or ""
> handle:close()
> diff --git a/tex/context/base/mkxl/lpdf-mis.lmt 
> b/tex/context/base/mkxl/lpdf-mis.lmt
> index 

[NTG-context] PDF, runner, and TikZ patches

2024-03-14 Thread Max Chernoff
Hi all,

I've had a few patches applied to my installation for a little while
now, so I figured that I should send them in. There's a diff at the end
of the email, and the modified files are attached [but rejected by the
mailing list, so sent separately to Hans]

 * In the definition of "featurecreep()" in "lpdf-mis.lmt",
   "structures.pages.tobesaved[i].status" should be "[...].state" to
   match the definition of "pages.save" in "strc-pag.lua". 
   
 * For the "resultof" runner in "util-sbx.lmt", the current io.popen
   mode only works with Windows. See the definition of "l_checkmodep" in
   "liolib.c".
   
 * Some of the pgfplots 3D shaders appear to be broken,
   see https://tex.stackexchange.com/a/708121 .
   
 * The TikZ "RGB" colour model does not currently work properly. This is
   internally used by "\usepgfplotslibrary[colorbrewer]" among others.
   See https://github.com/pgf-tikz/pgf/pull/1130 .
   
Thanks,
-- Max


diff --git a/tex/generic/pgf/utilities/pgfutil-context.def 
b/tex/generic/pgf/utilities/pgfutil-context.def
index eddab09ab..66edb0980 100644
--- a/tex/generic/pgf/utilities/pgfutil-context.def
+++ b/tex/generic/pgf/utilities/pgfutil-context.def
@@ -26,8 +26,17 @@
 \def\pgfutil@definecolor#1#2#3{\csname pgfutil@emu@#2\endcsname{#1}#3\@nil}

 
\def\pgfutil@emu@rgb#1#2,#3,#4\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{rgb}{#2,#3,#4}}}
-\def\pgfutil@emu@gray#1#2\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{rgb}{#2,#2,#2}}}
+\def\pgfutil@emu@gray#1#2\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{gray}{#2}}}
 
\def\pgfutil@emu@cmyk#1#2,#3,#4,#5\@nil{\expandafter\def\csname\string\color@#1\endcsname{\xcolor@{}{}{cmyk}{#2,#3,#4,#5}}}
+\def\pgfutil@emu@RGB#1#2,#3,#4\@nil{%
+\begingroup
+\pgfmathdivide@{#2}{255}\let\pgfutil@emu@RGB@r\pgfmathresult
+\pgfmathdivide@{#3}{255}\let\pgfutil@emu@RGB@g\pgfmathresult
+\pgfmathdivide@{#4}{255}\let\pgfutil@emu@RGB@b\pgfmathresult
+
\edef\pgf@marshal{\def\expandafter\noexpand\csname\string\color@#1\endcsname{%
+
\noexpand\xcolor@{}{}{rgb}{\pgfutil@emu@RGB@r,\pgfutil@emu@RGB@g,\pgfutil@emu@RGB@b}}}%
+\expandafter\endgroup\pgf@marshal
+}


 % no need for x colors (users can load it if needed)
diff --git a/tex/generic/pgfplots/pgfplotsmeshplothandler.code.tex 
b/tex/generic/pgfplots/pgfplotsmeshplothandler.code.tex
index 60d6274..106c490 100644
--- a/tex/generic/pgfplots/pgfplotsmeshplothandler.code.tex
+++ b/tex/generic/pgfplots/pgfplotsmeshplothandler.code.tex
@@ -2804,6 +2804,9 @@
 \def\pgfplotsretval{4}%
 \fi
 \fi
+ \if0\pgfplotsretval
+ \def\pgfplotsretval{5}
+ \fi
 \pgfkeyslet{/pgfplots/surf shading/shading type}\pgfplotsretval%
 %
 \pgfplotsplothandlermesh@set@shader@colormap
diff --git 
a/tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-luatex.def 
b/tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-luatex.def
index 0046daa..b563732 100644
--- a/tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-luatex.def
+++ b/tex/generic/pgfplots/sys/pgflibrarypgfplots.surfshading.pgfsys-luatex.def
@@ -61,7 +61,7 @@
 \pgfplotslibrarysurfusepath
 \endpgfpicture
 }%
- \immediate\saveboxresource resources{
+ \saveboxresource resources{
 /Pattern << \pgfplots@glob@TMPa >> % write the pattern resource dictionary
 }\pgfutil@tempboxa
 \leavevmode
diff --git a/tex/context/base/mkxl/util-sbx.lmt 
b/tex/context/base/mkxl/util-sbx.lmt
index b48d4a9..0ee8a16 100644
--- a/tex/context/base/mkxl/util-sbx.lmt
+++ b/tex/context/base/mkxl/util-sbx.lmt
@@ -393,7 +393,7 @@ local runners = {
 if trace then
 report("resultof: %s",command)
 end
-local handle = iopopen(command,"rb") -- already has flush
+local handle = iopopen(command,"r") -- already has flush
 if handle then
 local result = handle:read("*all") or ""
 handle:close()
diff --git a/tex/context/base/mkxl/lpdf-mis.lmt 
b/tex/context/base/mkxl/lpdf-mis.lmt
index 0f21cf9..a9cfe02 100644
--- a/tex/context/base/mkxl/lpdf-mis.lmt
+++ b/tex/context/base/mkxl/lpdf-mis.lmt
@@ -510,7 +510,7 @@ local function featurecreep()
 return -- fatal error
 end
 local label = p.viewerprefix or ""
-if p.status == v_stop then
+if p.state == v_stop then
 if not stopped then
 list[#list+1] = i - 1 -- pdf starts numbering at 0
 list[#list+1] = pdfdictionary {


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

maillist : ntg-context@ntg.nl / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki : https://wiki.contextgarden.net

[NTG-context] Re: Japanese

2024-03-14 Thread Otared Kavian
Dear Emmanuel,

Thank you for your reply: indeed I understand your approach, which is quite 
efficient. I am not at all good in coding, so I naively thought there would be 
a way for your setup to retrieve the information it needs from what the user is 
doing. Maybe once things are settled, Hans and Wolfgang will have a look in the 
Japanese part of ConTeXt so that the user can avoid to enter the setup included 
in the \directlua part.

Again thank you for what you are sharing.

Best regards: Otared

> On 14 Mar 2024, at 08:12, Emanuel Han via ntg-context  
> wrote:
> 
> Dear Otared,
> 
> when you read the lua code in the first \directlua{}, you should realize that 
> the dimensions of almost all layout elements are depending on the value of my 
> lua variable "paperSize".
> Thanks to defining the paper size first in lua, I can apply calculations of 
> numeric values.
> 
> The value of paperSize is later passed on to \setuppapersize via 
> \setuppapersize[\directlua{tex.print(paperSize)}]
> 
> Emanuel
> On März 13 2024, at 3:55 pm, Otared Kavian  wrote:
> Hi Emmanuel,
> 
> Thank you so much for the new setup for writing Japanese: I tested with both 
> files, and noticed that with the new version the output looks great.
> 
> I have a question about the code in the \directlua{} part of your setup: why, 
> for instance, the
> paperSize = « B5"
> is defined « by hand » there, instead of being retrieved from the command
> \setuppapersize[B5]
> issued by the user?
> 
> Actually I am using your setup for learning Japanese, and at my beginner’s 
> level I do separate words I am learning with spaces. While with the previous 
> version of your setup the lines were breaking womewhat strangely, but now the 
> spaces between words in the output are as I intended them to be (I should 
> also Thank Wolfgang Schuster for his insight with the \script[nihongo], and 
> indeed Hans for fixing so quickly the slightest bug).
> 
> It is really a great pleasure to be in this community where help comes from 
> everyone and features are given on demand !
> 
> Best regards: Otared
> 
> > On 10 Mar 2024, at 17:43, Emanuel Han via ntg-context  
> > wrote:
> >
> > Hi all,
> >
> > I added 
> > https://wiki.contextgarden.net/Chinese_Japanese_and_Korean#Meeting_the_JIS_X_4051_Requirements_for_Japanese_Text_Layout
> > with attached working example code and to-do list.
> >
> > Thanks for any contributions!
> >
> > The working example code is still a work in progress. Its text layout 
> > output meets already some of the requirements (see comments in the code). 
> > Among the ones to still be implemented are:
> >
> > • solid setting (no extra spacing between characters) 
> > https://www.w3.org/TR/jlreq/#fig1_8 if no requirement for line-adjustment 
> > https://www.w3.org/TR/jlreq/#term.line-adjustment
> > • aligning of the lines to the Kihon-hanmen (optimizing the code below in 
> > this regard)
> > • positioning and realm of headings https://www.w3.org/TR/jlreq/#fig3_1_9 
> > https://www.w3.org/TR/jlreq/#fig3_1_15 et al, and 
> > https://www.w3.org/TR/jlreq/#fig3_1_4
> > • positioning of yokugo-ruby https://www.w3.org/TR/jlreq/#fig2_3_24
> > • inline cutting note (warichu) https://www.w3.org/TR/jlreq/#fig2_4_1
> > • emphasis with sesame dot or bullet
> > • itemization https://www.w3.org/TR/jlreq/#fig2_5_6
> > • indenting of quotation paragraphs https://www.w3.org/TR/jlreq/#fig2_5_7
> > • tab setting https://www.w3.org/TR/jlreq/#fig2_6_1
> > • furiwake https://www.w3.org/TR/jlreq/#fig2_7_2
> > • jidori https://www.w3.org/TR/jlreq/#fig2_7_4
> > • math https://www.w3.org/TR/jlreq/#fig2_7_6 and 
> > https://www.w3.org/TR/jlreq/#fig2_7_62
> > • tategaki (writing vertically)
> > Best regards
> >
> > Emanuel
> > On März 2 2024, at 7:00 pm, Wolfgang Schuster 
> >  wrote:
> > Emanuel Han schrieb am 01.03.2024 um 16:23:
> >
> > Dear Wolfgang,
> >
> > thank you for your valuable remarks. I integrated them, see corrected 
> > attached example.
> >
> > Yes, correct layout examples exist. They're all showing vertical writing, 
> > but the rules and principles are exactly the same for horizontal writing.
> >
> > • position of the headers and footers: https://www.w3.org/TR/jlreq/#fig1_30
> >
> > See my attached gongitsune.tex example how you can squeeze text in a very 
> > narrow header/footer.
> >
> > • aligning lines to the text box: https://www.w3.org/TR/jlreq/#fig1_3
> >
> > You can use the lines key for \setuplayout to let ConTeXt calculate the 
> > necessary value for the text height.
> >
> > • protrusion of ruby: https://www.w3.org/TR/jlreq/#fig_ad1_6
> >
> > You're getting this for free because ruby text doesn't take up vertical 
> > space, in case vertical text is working it would now stick into the margins 
> > as expected.
> >
> > \starttext
> > \ruledhbox{a \ruby{x}{y} b}
> > \stoptext
> >
> >
> >
> > In my previous mail, I wrote wrong amounts of lines. They should be 46 
> > lines on one page, while the actual example doesn't show the 46th 

[NTG-context] Re: Japanese

2024-03-14 Thread Emanuel Han via ntg-context
Dear Otared,

when you read the lua code in the first \directlua{}, you should realize that 
the dimensions of almost all layout elements are depending on the value of my 
lua variable "paperSize".
Thanks to defining the paper size first in lua, I can apply calculations of 
numeric values.

The value of paperSize is later passed on to \setuppapersize via 
\setuppapersize[\directlua{tex.print(paperSize)}]
Emanuel
On März 13 2024, at 3:55 pm, Otared Kavian  wrote:
> Hi Emmanuel,
>
> Thank you so much for the new setup for writing Japanese: I tested with both 
> files, and noticed that with the new version the output looks great.
> I have a question about the code in the \directlua{} part of your setup: why, 
> for instance, the
> paperSize = « B5"
> is defined « by hand » there, instead of being retrieved from the command
> \setuppapersize[B5]
> issued by the user?
>
> Actually I am using your setup for learning Japanese, and at my beginner’s 
> level I do separate words I am learning with spaces. While with the previous 
> version of your setup the lines were breaking womewhat strangely, but now the 
> spaces between words in the output are as I intended them to be (I should 
> also Thank Wolfgang Schuster for his insight with the \script[nihongo], and 
> indeed Hans for fixing so quickly the slightest bug).
> It is really a great pleasure to be in this community where help comes from 
> everyone and features are given on demand !
> Best regards: Otared
> > On 10 Mar 2024, at 17:43, Emanuel Han via ntg-context  
> > wrote:
> >
> > Hi all,
> >
> > I added 
> > https://wiki.contextgarden.net/Chinese_Japanese_and_Korean#Meeting_the_JIS_X_4051_Requirements_for_Japanese_Text_Layout
> > with attached working example code and to-do list.
> >
> > Thanks for any contributions!
> >
> > The working example code is still a work in progress. Its text layout 
> > output meets already some of the requirements (see comments in the code). 
> > Among the ones to still be implemented are:
> >
> > • solid setting (no extra spacing between characters) 
> > https://www.w3.org/TR/jlreq/#fig1_8 if no requirement for line-adjustment 
> > https://www.w3.org/TR/jlreq/#term.line-adjustment
> > • aligning of the lines to the Kihon-hanmen (optimizing the code below in 
> > this regard)
> > • positioning and realm of headings https://www.w3.org/TR/jlreq/#fig3_1_9 
> > https://www.w3.org/TR/jlreq/#fig3_1_15 et al, and 
> > https://www.w3.org/TR/jlreq/#fig3_1_4
> > • positioning of yokugo-ruby https://www.w3.org/TR/jlreq/#fig2_3_24
> > • inline cutting note (warichu) https://www.w3.org/TR/jlreq/#fig2_4_1
> > • emphasis with sesame dot or bullet
> > • itemization https://www.w3.org/TR/jlreq/#fig2_5_6
> > • indenting of quotation paragraphs https://www.w3.org/TR/jlreq/#fig2_5_7
> > • tab setting https://www.w3.org/TR/jlreq/#fig2_6_1
> > • furiwake https://www.w3.org/TR/jlreq/#fig2_7_2
> > • jidori https://www.w3.org/TR/jlreq/#fig2_7_4
> > • math https://www.w3.org/TR/jlreq/#fig2_7_6 and 
> > https://www.w3.org/TR/jlreq/#fig2_7_62
> > • tategaki (writing vertically)
> > Best regards
> >
> > Emanuel
> > On März 2 2024, at 7:00 pm, Wolfgang Schuster 
> >  wrote:
> > Emanuel Han schrieb am 01.03.2024 um 16:23:
> >
> > Dear Wolfgang,
> >
> > thank you for your valuable remarks. I integrated them, see corrected 
> > attached example.
> >
> > Yes, correct layout examples exist. They're all showing vertical writing, 
> > but the rules and principles are exactly the same for horizontal writing.
> >
> > • position of the headers and footers: https://www.w3.org/TR/jlreq/#fig1_30
> >
> > See my attached gongitsune.tex example how you can squeeze text in a very 
> > narrow header/footer.
> >
> > • aligning lines to the text box: https://www.w3.org/TR/jlreq/#fig1_3
> >
> > You can use the lines key for \setuplayout to let ConTeXt calculate the 
> > necessary value for the text height.
> >
> > • protrusion of ruby: https://www.w3.org/TR/jlreq/#fig_ad1_6
> >
> > You're getting this for free because ruby text doesn't take up vertical 
> > space, in case vertical text is working it would now stick into the margins 
> > as expected.
> >
> > \starttext
> > \ruledhbox{a \ruby{x}{y} b}
> > \stoptext
> >
> >
> >
> > In my previous mail, I wrote wrong amounts of lines. They should be 46 
> > lines on one page, while the actual example doesn't show the 46th line.
> >
> > It would be important to identify the reason why only 24 characters are 
> > used to create a line when 25 could be used. Then we can develop a method 
> > to turn that mechanism off or circumvent it.
> > Quotation from https://www.w3.org/TR/jlreq:
> > In principle, when composing a line with ideographic (cl-19), hiragana 
> > (cl-15) and katakana (cl-16) characters, no extra spacing appears between 
> > their character frame. This is called solid setting (see Figure 5).
> >
> > 1. ConTeXt has a mechanism to typeset Japanese texts.
> >
> > 2. There are flaws in the output it produces but this