Re: [NTG-context] calculating optimal height of textblock

2021-04-28 Thread Hans Hagen

On 4/28/2021 2:07 PM, denis.ma...@ub.unibe.ch wrote:

how do you usually calcultate your layouts? For example in this example, 
the third value for height is not really helpful as there will never be 
a complete line :


you can use

  lines=40,

instead of height

Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] custom zig zag sidebars

2021-04-28 Thread Hans Hagen

On 4/28/2021 5:27 PM, mf wrote:

Hello,

I made an experiment to add alternatives to sidebars (see attachment).

I discovered the sidebar is drawn by anch_sidebars_draw in 
metapost/context/base/mpiv/mp-apos.mpiv.


I've redefined it locally to add alternatives.

To make fancy, zig zag bars I defined a macro, draw_pattern_bar, that 
draws a bar repeating a pattern which is a path connecting (0,0) and (1,0).


The macro has 3 parameters (actually it has more params, but the 
remainder are anch_sidebars_draw params):


- a pattern, which is a path from (0,0) to (1,0) that should have a 
vertical size = 1; it's a sort of waveform


- a pattern length, by which the pattern is xsized

- a pattern width, by which the pattern is ysized

Then the pattern is rotated along the bar direction (so -90 degrees) and 
drawn many times until it covers the bar length.


A proposal and a question:

- patternlength and patternwidth could become \setupsidebar params; 
alternative (=2,3,4...) could be used to specify the pattern (a sort of 
waveform); currently alternative=0 is a solid bar and alternative=1 is a 
dashed one


- in case of long patterns (a patternlength spanning more lines of text) 
the last replica of the pattern should be clipped not to exceed the last 
line of the sidebarred text (see the last example): how can that be done?

how about

def draw_pattern_bar(expr a, b, pattern, patternlength, patternheight, 
linewidth, linecolor) =

draw image (
begingroup ;
save p, q, stp ;
pair p, q, stp ;
stp := ( ( b - a ) / arclength( a -- b ) ) * patternlength ;
path q ; q := pattern xscaled patternlength yscaled 
patternheight rotated (angle(stp)) ;

p := a ;
forever :
draw
q shifted p
withpen pencircle scaled linewidth
withcolor linecolor ;
p := p + stp ;
exitif arclength( a -- p ) > arclength( a -- b ) ;
endfor ;
endgroup ;
clip currentpicture to
(xpart llcorner currentpicture, ypart b) --
(xpart lrcorner currentpicture, ypart b) --
(xpart urcorner currentpicture, ypart a) --
(xpart ulcorner currentpicture, ypart a) -- cycle ;
) ;
enddef ;


-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


[NTG-context] custom zig zag sidebars

2021-04-28 Thread mf

Hello,

I made an experiment to add alternatives to sidebars (see attachment).

I discovered the sidebar is drawn by anch_sidebars_draw in 
metapost/context/base/mpiv/mp-apos.mpiv.


I've redefined it locally to add alternatives.

To make fancy, zig zag bars I defined a macro, draw_pattern_bar, that 
draws a bar repeating a pattern which is a path connecting (0,0) and (1,0).


The macro has 3 parameters (actually it has more params, but the 
remainder are anch_sidebars_draw params):


- a pattern, which is a path from (0,0) to (1,0) that should have a 
vertical size = 1; it's a sort of waveform


- a pattern length, by which the pattern is xsized

- a pattern width, by which the pattern is ysized

Then the pattern is rotated along the bar direction (so -90 degrees) and 
drawn many times until it covers the bar length.


A proposal and a question:

- patternlength and patternwidth could become \setupsidebar params; 
alternative (=2,3,4...) could be used to specify the pattern (a sort of 
waveform); currently alternative=0 is a solid bar and alternative=1 is a 
dashed one


- in case of long patterns (a patternlength spanning more lines of text) 
the last replica of the pattern should be clipped not to exceed the last 
line of the sidebarred text (see the last example): how can that be done?


Massi


\definesidebar[zigzag1][rulecolor=black,distance=4pt,rulethickness=1pt,alternative=2]
\definesidebar[zigzag2][rulecolor=red,distance=4pt,rulethickness=1pt,alternative=3]
\definesidebar[wave1][rulecolor=blue,distance=4pt,rulethickness=1pt,alternative=4]
\definesidebar[wave2][rulecolor=cyan,distance=4pt,rulethickness=1pt,alternative=5]
\definesidebar[obliquedashes][rulecolor=darkgreen,distance=4pt,rulethickness=1pt,alternative=6]
\definesidebar[longobliquedashes][rulecolor=orange,distance=10pt,rulethickness=1pt,alternative=7]

\startMPcode
def draw_pattern_bar(expr a, b, pattern, patternlength, patternheight, linewidth, linecolor) =
begingroup ;
save p, z, step ;
pair p, z, step ;
step := ( ( b - a ) / arclength( a -- b ) ) * patternlength ;
path z ; z := pattern xscaled patternlength yscaled patternheight rotated (angle(step)) ;
p := a ;
forever :
draw
z shifted p
withpen pencircle scaled linewidth
withcolor linecolor ;
p := p + step ;
exitif arclength( a -- p ) > arclength( a -- b ) ;
endfor ;
endgroup ;
enddef ;

% from metapost/context/base/mpiv/mp-apos.mpiv
def anch_sidebars_draw (expr p_b_self, p_e_self, y_b_self, y_e_self, h_b_self, d_e_self,
x, y, w, h, alternative, distance, linewidth, linecolor, topoffset, bottomoffset) =
% beware, we anchor at (x,y)
begingroup ;
if alternative = 1 :
interim linecap := rounded ;
else :
interim linecap := butt ;
fi ;
save a, b ; pair a, b ;
if p_b_self = p_e_self :
a := (-distance,y_b_self+h_b_self-y) ;
b := (-distance,y_e_self-d_e_self-y) ;
elseif RealPageNumber = p_b_self :
a := (-distance,y_b_self+h_b_self-y) ;
b := (-distance,0) ;
elseif RealPageNumber = p_e_self :
a := (-distance,h) ;
b := (-distance,y_e_self-d_e_self-y) ;
else :
a := (-distance,h) ;
b := (-distance,0) ;
fi ;
a := (xpart a, min(ypart a + topoffset,   h)) ;
b := (xpart b, max(ypart b - bottomoffset,0)) ;
if alternative = 2 :
draw_pattern_bar( a, b, ((0,0)--(0.25,-0.5)--(0.75,0.5)--(1,0)), 2pt, 2pt, linewidth, linecolor ) ;
elseif alternative = 3 :
draw_pattern_bar( a, b, ((0,0)--(0.25,-0.5)--(0.75,0.5)--(1,0)), 4pt, 1.5pt, linewidth, linecolor ) ;
elseif alternative = 4 :
draw_pattern_bar( a, b, ( ((0,0) .. controls (0,0.5) and (0.5,0.5) .. (0.5,0)) -- ((0.5,0) .. controls (0.5,-0.5) and (1,-0.5) .. (1,0)) ), 6pt, 4pt, linewidth, linecolor ) ;
elseif alternative = 5 :
draw_pattern_bar( a, b, ( (0,0) .. controls (0,1) and (1,1) .. (1,0) ), 4pt, 2pt, linewidth, linecolor ) ;
elseif alternative = 6 :
draw_pattern_bar( a, b, ( (0,0.5) .. (1,-0.5) ), 4pt, 2pt, linewidth, linecolor ) ;
elseif alternative = 7 :
draw_pattern_bar( a, b, ( (0,-0.5) .. (1,0.5) ), 22pt, 5pt, linewidth, linecolor ) ;
else :
draw
a -- b
if alternative = 1 :
dashed (withdots scaled (linewidth/2))
fi
withpen pencircle scaled linewidth
withcolor linecolor ;
fi ;
endgroup ;
enddef ;
\stopMPcode

\starttext
\startsidebar[zigzag1]\input knuth\relax\stopsidebar\par
\blank
\startsidebar[zigzag2]\input sapolsky\relax\stopsidebar\par
\blank
\startsidebar[wave1]\input knuth\relax\stopsidebar\par
\blank
\startsidebar[wave2]\input sapolsky\relax\stopsidebar\par
\blank
\startsidebar[obliquedashes]\input knuth\relax\stopsidebar\par
\blank
\startsidebar[longobliquedashes]\input 

[NTG-context] calculating optimal height of textblock

2021-04-28 Thread denis.maier
Hi,

how do you usually calcultate your layouts? For example in this example, the 
third value for height is not really helpful as there will never be a complete 
line :

=
\setupbodyfont[10pt]

\definepapersize[test][width=140mm,height=208mm]
\setuppapersize[test][test]

\setuplayout[reset]
\setuplayout[backspace=17mm,
  topspace=19mm,
  header=0mm,
  footerdistance=4mm,
  footer=5mm,
  width=105mm,
  %height=174mm,
  height=178mm,
  %height=177mm, % does not suffice for 
a complete line
  rightmargin=0mm,
  leftmargin=0mm,
  ]

\startsetups[mypenalties]
\setdefaultpenalties
\setpenalties\clubpenalties{2}{0}
\setpenalties\widowpenalties{2}{0}
\setpenalties\displaywidowpenalties{2}{0}
\stopsetups
\setuplayout[setups=mypenalties]

%\showframe
\showmakeup
%\showsetups

\starttext

\dorecurse{5}{\input knuth\par}

\stoptext
=

How do you do this usually? Any best-practices? Hints? Trial and error seems to 
work ok, but maybe there is a more efficient method...

Best
Denis
___
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
___


Re: [NTG-context] \setupalign[height] and \setupalign[line] in LMTX

2021-04-28 Thread denis.maier
Ok, after dabbling around a bit more, I can now come up with the following 
example



\setuppapersize[A5][A5]
\showframe

\setuptolerance[vertical,stretch]

%\setupalign[line]
%\setupinterlinespace[stretch=0.1] % vertical stretching seems to kick in for 
stretch !=0, no matter how small

\setupalign[height]
\setupinterlinespace[stretch=0.001] % vertical stretching seems to kick in for 
stretch !=0, no matter how small

\setupdelimitedtext[blockquote]
   [style={\switchtobodyfont[x]},
   spacebefore={medium,flexible},
   leftmargin=no]

\starttext

\dorecurse{10}{
\input knuth

\startblockquote
\input knuth
\stopblockquote

\input knuth
}

\stoptext



Two noteworthy things:

  1.  In LMTX you'll need \setupinterlinespace[stretch=X] with X not 0 for 
vertical to kick in.
  2.  \setupalign[line] insists to fill the last page completely.

Denis

Von: Maier, Denis Christian (UB)
Gesendet: Montag, 26. April 2021 11:34
An: 'mailing list for ConTeXt users' 
Betreff: AW: \setupalign[height] and \setupalign[line] in LMTX

Hi,

sorry to be such a nuisance, but i'd still love to hear if I'm missing 
something or if something is going off the rails in LMTX.

Best,
Denis


Von: Maier, Denis Christian (UB)
Gesendet: Donnerstag, 22. April 2021 15:07
An: 'mailing list for ConTeXt users' 
mailto:ntg-context@ntg.nl>>
Betreff: \setupalign[height] and \setupalign[line] in LMTX

Hi,

\setupalign[height] and \setupalign[line] seem to have no effect in a  LMTX. Do 
I need to change something?

Best,
Denis


```
\setuppapersize[A5][A5]
\showframe
%\setupalign[line]
\setupalign[height]

\setupdelimitedtext[blockquote]
   [
   
before={\setupindenting[yes]\tfx\setupinterlinespace},
   
spacebefore=medium,
   indentnext=no,
   leftmargin=no,
   rightmargin=no,
   ]


\starttext

\dorecurse{10}{
\input knuth

\startblockquote
\input knuth
\stopblockquote

\input knuth
}

\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
___


Re: [NTG-context] wrong line break in recent LMTX

2021-04-28 Thread Hans Hagen

On 4/27/2021 9:00 PM, Pablo Rodriguez wrote:

On 4/27/21 8:57 AM, Hans Hagen wrote:

[...]
as mentioned in an earlier mail, after decades of utf in tex we should
use the normal symbols instead ... you can disable collapsing with

\nohyphencollapsing

but then you need to enable the tlig font feature. In days when often
texts is imported from elsewhere and editors can show these dashes we
need to adapt


Not sure I understand your explanation.

I have been using UTF-8 as charset for my documents since 2002
(otherwise polytonic Greek was unreadable for me).

It was also more readable to use real character for em- and en-dashes
than three or two hyphens.

It took me a while since I accidentally discovered a document with a
wrong line break between a real em-dash and a point followed by a
footnote number.

So my question is what \hccode stands for?


hyphencharcode

good old tex only has \exhyphenchar, in luametatex we can tag any char 
as such


in traditional tex th ehyphenation, ligature building and kerning wre 
integrated, so handling - -- ---  -- is kind of complex


in luatex these stages are split but there's still messy logic wrt 
successive hyphens


in luametatex the hyphenation machinery has all kind of extra controls 
and the hccode mechanism was introduced as side effect of a feedback 
mechanism that also can handle compound words better (althoiugh one can 
of course dispute the 'better' part)



 From luametatex.pdf in the distribution, I see that this is a LuaTeX
primitive, but luatex.pdf doesn’t mention it.
sure, it's a luametatex primitive, but that is true for some more, like 
the detailed control of how characters are treated in various stages


Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | 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://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___