12:24 AM
How to expand to wd0?

\def\contentWidth#1%
{%
\setbox0\hbox{#1}%
\wd0
}
% \contentWidth{ } %! Missing number, treated as zero.
% \vrule\hspace{\contentWidth{ }}hello %! Missing number, treated as zero.
% \the\contentWidth{ } %! You can't use \setbox' after \the.

6 hours later…
6:35 AM
@bp2017 \the\wd0\relax

7:18 AM
@bp2017 As @JosephWright said. Note that \the will expand the width to a string. You don´t need it in places where a dimen or glue is already expected. The purpose of \relax is just to guard against more digits, or possibly premature macro expansion (tex expands macros while reading the number). A space would do just as well, but is less obvious.

2 hours later…
9:32 AM
@bp2017 your two cases there are the same, in both cases you are just passing a number to the box commands \myBox is defined to be a number (actually it is a character token defined via \chardef)

4 hours later…
1:06 PM
3
Another palindrome :-)

@egreg you're getting slow :)
@PhelypeOleinik that one is impressive, but the comma is wrong (if I say this @DavidCarlisle can't say it)

@Skillmon I got distracted by a student asking about an exam. :-( You could add some discussion about an optional argument that appears to be mandatory and the reason for \IfValueT.

@Skillmon I've got another one of these a few months ago. @DavidCarlisle will be so amazed by my palindrome he'll forget to complain about the comma ;-)

@egreg sorry to hear :) Good idea though, thanks.

@PhelypeOleinik the comma is in the wrong place

1:18 PM
@PhelypeOleinik sorry, I couldn't protect you.

@DavidCarlisle You're just jealous ;-)

@PhelypeOleinik I have no need to be jealous, I have a badge (along with @egreg and @UlrikeFischer, it seems)

@DavidCarlisle is it golden, though?

@DavidCarlisle There ^^

@PhelypeOleinik position of the badge symbols isn't right.

1:31 PM
@Skillmon My HTML skills say that's impossible to fix :P

@PhelypeOleinik use an image manipulation tool to remove them?

@Skillmon Too much effort. I'll wait for another with the comma in the right place ;-)

1:47 PM
@DavidCarlisle καλως ηρθες στο κλαμπ ;-)

@UlrikeFischer που κάλεσε τον άλλο άνθρωπο;

2:02 PM
@DavidCarlisle I have a much higher ratio of votes per answer in the tag.

2:14 PM
A brief question, may I use \relax inside a newly defined command foobar in order for \foobar not to gobble up whitespace? Or are {\foobar} and \foobar{} the way to go here?

@0xC0000022L \foobar{} is always the way to go. There is xspace, but depending on how you use it, it does not always work as advertised, so \foobar{} is normally what is recommended. \relax will not do anything.

Thanks, @daleif

3:01 PM
@MarcelKrüger I merged the embolden code - it works really fine.

3:43 PM
Based on experimentation, it seems that calls to tex.sprint in LuaTeX are not persistent, in the sense that a macro defined in one call isn't callable in a different call. But I don't why this should be the case. E.g.
print = tex.sprint
print([[\renewcommand{\Name}{foo}]])
print([[ Hello, \Name ]])
As usual, I'm probably missing something.
Oh, \renewcommand won't work the first time. Hmm.

@FaheemMitha Of course not, clue is in the name ;)

@JosephWright Doesn't work with \newcommand either, though.
No wait, it does, sorry.
Is that a variation that will define if not already defined, and redefine if already defined?
According to:
150


@FaheemMitha No, there's \providecommand though, so if you like you can \providecommand{\foo}{}\renewcommand{\foo}{...} to force the issue

Use:
\providecommand\foo{}
\renewcommand\foo{...}
@JosephWright Is that the best option available?

@FaheemMitha Depends on what you mean by 'best'
@FaheemMitha You could just \def the command if you really want to force it

3:52 PM
@JosephWright Right.

@JosephWright, if I do \the\wd0\relax, I won't be able to use \wd0 as a dim:
\vrule\hspace{\contentWidth{ }}hello % WON'T WORK (AND IT DOESN'T WORK EVEN WITHOUT \the)

@HaraldHanche-Olsen, yes, I know it will expand the width to a string. But I *do* need wd0 in places where a dimen is expected (not a string).

I just need \contentWidth

\def\contentWidth#1%
{%
\setbox0\hbox{#1}%
\wd0
}

to expand to \wd0 (not \the\wd0) so that it works like \wd0 (but \setbox0 is preventing it to work in such way, and prefixing \wd0 with \the ruins the dimen by expanding to string).

@bp2017 you can't (outside luatex) typeset a box and take its width using expansion. That is why with the calc package (with its \widthof command) never uses primitive length assignments, it always uses \setlength\zzz}{... some expression...]

@DavidCarlisle Can't be done in LuaTeX either, I think

@bp2017 you can use 3pt as a dimen anywhere you can use \wd0 other than an assignment such as \wd0=5pt and it's unlikely you want an assignment after such a measurement construct?
@JosephWright can't you construct a horizontal box purely in Lua?

@DavidCarlisle Unless Hans altered this, it used to be necessary to pass back to TeX ...

4:02 PM
@JosephWright tex.setbox (n,nodelist) so as long as you can get a list of nodes....

@DavidCarlisle Yes, was just reading that; not really the same as doing the TeX operation
@DavidCarlisle To do \setbox\foo=\hbox{...} I think you still need tex.print(), so it's still not expandable

@JosephWright that depends how far you have gone with avoiding tex I think, if you have the lua set up to typeset the string .... to a node list then you can assign that to a box

@DavidCarlisle Sure, but I think the question here isn't really of that type

@JosephWright oh, agreed: of course not:-)
@bp2017 the usual device is to pass in an extra argument to take the result, so rather than your \contentwidth latex has \settowidth\mylength{some text here} \hspace{\mylength} rather than trying to inline the length setting inside the \hspace

4:17 PM
@bp2017 Neither \setbox nor \hbox are expandable, so that approach is doomed. It really does take some effort to wrap your mind around the whole macro expansion thing. LaTeX, of course, has been carefully designed to not expose users to this difficulty.

5:11 PM
@JosephWright, @DavidCarlisle, @HaraldHanche-Olsen, thank you. I decided to use expl3 for this particular macro (by defining a function with cs_new and setting a dim passed to it).

It would've been helpful to know how to check (from inside the function) whether "n" parameter is empty braces in expl3.

Is there any way/hack in TFM fonts to replace a single glyph by another glyph, something like ligatures but involving a single glyph on the left side of the substitution.
(not using macros)

Mac people: will you upgrade to Catalina? (now on preview)
I am stuck on High Sierra and cannot upgrade to Mojave due to lack of hardware support.

@bp2017 so ending up as a re-implementation of \settowidth ?
@KhaledHosny vf wrapper is usual way, I suppose

5:30 PM
@DavidCarlisle hmm, right. Does not help with what I'm trying to do.

@KhaledHosny if you restrict to luatex/harftex you can use the lua interface to make a virtual font without actually making the separate file, but in xetex/pdftex things are harder...

@DavidCarlisle I'm trying to implement the tlig feature that @UlrikeFischer requested, and I had this idea of letting the old TFM machinery in the engine handle it (I basically insert ligature entries into the font structure as if it were read from TFM file) and it works for ligatures, but can't handle, say, turning ' into left single quote.
@DavidCarlisle hmm, not sure if I can get this to play nice with the other shaper stuff. But I never worked with LuaTeX virtual fonts, so I'm a bit in the dark here.

@KhaledHosny let me find an example on site...

@DavidCarlisle I tried to replace the entries in the font characters, but since after shaping HarfBuzz will return glyph indices, it won't "see" the change I made (since it reads data directly from the font file)
(I can of course replace the characters before I send them to HarfBuzz, but this will make my little neat hack a bit uglier as it would be done differently for ligatures and single substitutions). May be I should just do that.
are  and '' broken in luaotfload? they seem to produce two single quotes instead of double quotes

5:45 PM
@KhaledHosny works fine for me. Do you have an example?

It might be my broken test file, let me try a clean one.
@UlrikeFischer ah, broken in mode=base but fine in mode=node (I was testing with base mode assuming it would the closes to TFM files).

@KhaledHosny this here works fine for me
\documentclass{article}

\begin{document}
\font\test{file:lmroman10-regular.otf:mode=base;+tlig;}\test
L'arbre abc''
\end{document}

\input harfload.sty
\def\s{20pt}
\font\test=qx-lmr10 at \s\test
H'' h's i' f--f f---f f-f ! ? ,,f'' <<f>>\par
\font\test="[lmroman10-regular.otf]:+tlig;mode=harf" at \s\test
H'' h's i' f--f f---f f-f ! ? ,,f'' <<f>>\par
\font\test="[lmroman10-regular.otf]:+tlig;mode=node" at \s\test
H'' h's i' f--f f---f f-f ! ? ,,f'' <<f>>\par
\font\test="[lmroman10-regular.otf]:+tlig;mode=base" at \s\test
H'' h's i' f--f f---f f-f ! ? ,,f'' <<f>>\pa
\font\test="[lmroman10-regular.otf]:mode=base" at \s\test
@UlrikeFischer ^

@KhaledHosny looks good. Is it online?
@KhaledHosny (I wouldn't mind if the ! and ? weren't there ...

6:01 PM
@UlrikeFischer cleaning up and will commit soon. Notice the last line (that is base mode) there are two quotes not a double one
@UlrikeFischer I wouldn't mind either, but Computer Modern have them, so why not (it doesn't have ,, <<>> though, and these I'd be more happy to remove, but IIRC the XeTeX mapping file has them)

@KhaledHosny oh I see, you are right. I get it too.

6:20 PM
@PauloCereda Most likely. But my wife is addicted to dashboard, so she won´t. Not soon, at least.

@HaraldHanche-Olsen Ah yes, dashboard will be gone in the next version...

6:49 PM
@UlrikeFischer Another difference between base and node, \char"2013- will produce em dash in base mode, but en dash followed by hyphen in node mode.

7:01 PM
@KhaledHosny I don't think that this is really a problem if base mode and node mode differ - base mode is used mostly in math anyway. But harf and node should be similar.

@UlrikeFischer Now that is problem, I'm implmenting these ligatures really as TeX ligatures, so they behave like base mode ligatures and I have no much control over that (and \char"7d- with TFM Computer Modern does produce an em dash as well, so node mode is the outlier here).

@KhaledHosny oh you mean the "\char"2013-" case? I wouldn't worry about that at all. The standard stuff should work.

2 hours later…
8:53 PM
@marmot vanishing comments I see:-)

@DavidCarlisle I knew you would like it. ;-)