TeX - LaTeX Asked by Jewdokija on January 31, 2021
The codes of the two vtop
in the example below look very similar.
Difference is:
hbox{ccchfill}
. Due to hrule
no baselineskip
-glue is inserted between bbb
and ccc
. TeX does not go into horizontal mode. No parskip
-glue is inserted between bbb
and ccc
. (No vertical glue at all is inserted between bbb
and ccc
.)ccc
. Due to hrule
no baselineskip
-glue is inserted between bbb
and ccc
. TeX does go into horizontal mode. parskip
-glue is inserted between bbb
and ccc
.Now assume a situation where you don’t know if TeX will go into horizontal mode after the hrule
but in any case you don’t want parskip
-glue/any vertical glue after the hrule
. In any case you want the thing to look like in case 1.
Is there a method to cancel or prevent parskip
glue in case material following the hrule
switches to horizontal mode without knowing before if this switching will happen?
parindent=0ex
parskip=4cm
baselineskip=2cm
hbox tohsize{%
vtop{hsize=.3hsize
hbox{aaa}
hbox{bbb}
hrule height 0mm depth 0mmrelax
hbox{ccc} %<- TeX stays in restricted vertical mode
parhbox tohsize{This is case 1hfill}
}hfillvrulehfill
vtop{hsize=.3hsize
hbox{aaa}
hbox{bbb}
hrule height 0mm depth 0mmrelax
ccc %<- TeX switches to horizontal mode
parhbox tohsize{This is case 2hfill}
}%
}
bye
You could do something like this
parindent=0ex
parskip=4cm
baselineskip=2cm
hbox tohsize{%
vtop{hsize=.3hsize
hbox{aaa}
hbox{bbb}
hrule height 0mm depth 0mmrelax
everypar{setbox0=lastboxendgrafeverypar{}vskip-2parskip}
hbox{ccc} %<- TeX stays in restricted vertical mode
parhbox tohsize{This is case 1hfill}
}hfillvrulehfill
vtop{hsize=.3hsize
hbox{aaa}
hbox{bbb}
hrule height 0mm depth 0mmrelax
everypar{setbox0=lastboxendgrafeverypar{}vskip-2parskip}
ccc %<- TeX switches to horizontal mode
parhbox tohsize{This is case 2hfill}
}%
}
bye
Answered by David Carlisle on January 31, 2021
This answer is an attempt at further developing the answer of David Carlisle which aims at the hook everypar
whose tokens are delivered whenever TeX due to switching to horizontal mode has just delivered vertical parskip
-glue and started a horizontal list by inserting the hbox
of width parindent
.
As you focus on the "codes of the vtop
" and not on the vtop
itself I assume that the desired method is to work out also in (non-internal) vertical mode where probably some begingroup
..endgroup
-thingie might precede and more paragraphs might follow the hbox{ccc}
/ccc
/noindent ccc
(?)-thingie.
Probably you can mess around with everypar
, everyhbox
, everyvbox
, everymath
, everydisplay
to make sure that not only the next paragraph but generally the next thing that is typeset will cancel the changes to everyar
. I have not yet thought about whether there are more obscure situations to consider in regard to "the next thing that is typeset".
In the example below the token skiprestore
respective resetskiprestore
is prepended permanently to each of the above-mentioned hooks. Usually these macros are no-ops.
The macro makemydamnverticalgap
redefines
resetskiprestore
to redefine skiprestore
and resetskiprestore
as no-ops.skiprestore
to apply the redefined resetskiprestore
and to do some negative vertical skipping for cancelling out vertical parskip
-glue, to do noindent
in case the hbox
inserted for starting the horizontal list had the width 0pt
.I decided for prepending tokens to the hooks permanently because then redefining these tokens can be done in terms of global
which means that the desired changes will survive the wrapping into groups.
I don't know about the best way of implementing such a thing in LaTeX 2ε where the kernel itself plays around with all these every...
-hooks.
Also in LaTeX there is, e.g., the package everyhook which allows you to mess around with the every...
-hooks. Be aware that the current release (everyhook v1.2, dated 2014/11/26) has a bug which leads to amounts of consecutve hashes being halveed , e.g., ########
being halved to ####
, whenever e.g., PushPreHook
, PopPreHook
, PushPostHook
, PopPostHook
and the like is carried out. (I addressed the issue on the package's GitHub-repository some months ago.)
parindent=3ex
parskip=.5cm
longdefexchange#1#2{#2#1}
longdeffirstoftwo#1#2{#1}
longdefsecondoftwo#1#2{#2}
newboxmybox
longgdefprependtohook#1#2{%
#1=expandafter{romannumeral0expandafterexchangeexpandafter{the#1}{ #2}}
}%
prependtohookeverypar{skiprestore}
prependtohookeveryhbox{resetskiprestore}
prependtohookeveryvbox{resetskiprestore}
prependtohookeverymath{resetskiprestore}
prependtohookeverydisplay{resetskiprestore}
% I am not sure whether resetskiprestore should be done with other hooks also.
newboxmybox
gdefskiprestore{}%
gdefresetskiprestore{}%
longdefmakemydamnverticalgap#1{%
endgraf
hrule height 0mm depth 0mmrelaxnobreak
kern#1nobreak
hrule height 0mm depth 0mmrelax
gdefresetskiprestore{gdefskiprestore{}gdefresetskiprestore{}}%
gdefskiprestore{%
resetskiprestore
setboxmybox=lastbox
vskip-2parskip
endgrafifdimwdmybox>0pt elseexpandafternoindentfi
}%
ignorespaces
}%
noindent This is some paragraph.xleadershbox{This is some paragraph.}hfill This is some paragraph.
begingroup
makemydamnverticalgap{2cm}
endgroup
hbox{This does not switch to horizontal mode. There should be a vertical 2cm gap above this.}
This is another paragraph.
noindent This is some paragraph.xleadershbox{This is some paragraph.}hfill This is some paragraph.
begingroup
makemydamnverticalgap{2cm}
endgroup
leavevmode This does switch to horizontal mode. There should be a vertical 2cm gap above this.
This is another paragraph.
noindent This is some paragraph.xleadershbox{This is some paragraph.}hfill This is some paragraph.
begingroup
makemydamnverticalgap{2cm}
endgroup
noindent This does switch to horizontal mode. There should be a vertical 2cm gap above this.
This is another paragraph.
xleadersvbox{hrule height 0pt width 0ptpar This is another paragraph.}vfillbreak
parindent=1cm
parskip=4cm
baselineskip=2cm
hbox tohsize{%
vtop{hsize=.25hsize
hbox{aaa}
hbox{bbb}
makemydamnverticalgap{0cm}%
hbox{ccc} %<- TeX stays in restricted vertical mo-de
parvtop{noindent This is case 1 - TeX{} staying in restricted vertical mo-de}
}hfillvrulehfill
vtop{hsize=.25hsize
hbox{aaa}
hbox{bbb}
makemydamnverticalgap{0cm}%
ccc %<- TeX switches to horizontal mo-de
parvtop{noindent This is case 2 - TeX{} switching to horizontal mo-de and inserting {ttstringpar-in-dent}}
}hfillvrulehfill
vtop{hsize=.25hsize
hbox{aaa}
hbox{bbb}
makemydamnverticalgap{0cm}%
noindent ccc %<- TeX switches to horizontal mo-de
parvtop{noindent This is case 3 - TeX{} switching to horizontal mo-de and not inserting {ttstringpar-in-dent}}
}
}
bye
Answered by Ulrich Diez on January 31, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP