Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch \symbol under XeTeX (or fix upstream) #124

Closed
wspr opened this issue Feb 10, 2019 · 22 comments
Closed

Patch \symbol under XeTeX (or fix upstream) #124

wspr opened this issue Feb 10, 2019 · 22 comments

Comments

@wspr
Copy link
Contributor

wspr commented Feb 10, 2019

Brief outline of the bug

In XeTeX \Uchar should be used instead of \char in some cases.
More details here: latex3/unicode-math#499

Minimal example showing the bug

\RequirePackage{latexbug}
\documentclass{article}
\begin{document}
\font\x="[STIX2Math.otf]"\relax\x
{$\tracingall\symbol{"1D400}$}
\end{document}

Log file (required) and possibly PDF file

\symbol #1->\char #1\relax 
#1<-"1D400
{\char}
./small.tex:8: Bad character code (119808).
<to be read again> 
                   \relax 
l.8 {$\tracingall\symbol{"1D400}
@stale
Copy link

stale bot commented Nov 28, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 28, 2019
@davidcarlisle
Copy link
Member

\symbol isn't generally expandable so this should probably be fixed upstream, unless we want to make symbol expandable in all engines. Is it reported at the xetex tracker?

@josephwright
Copy link
Member

@davidcarlisle But \symbol is already robust, so using \Uchar internally makes no odds.

@u-fischer
Copy link
Member

@davidcarlisle I see no reason why we shouldn't do this

\ifx\Umathcode\@undefined
\DeclareRobustCommand\symbol[1]{\char #1\relax}
\else
\DeclareRobustCommand\symbol[1]{\Uchar #1\relax}
\fi

@davidcarlisle
Copy link
Member

@josephwright it isn't really about \symbol (and the extra \relax from the \protect wouldn't hurt here, it is about \char

I don't think this should give an error in xetex (it works in luatex)


\documentclass{article}
\begin{document}
\font\x="[STIX2Math.otf]"\relax\x
{$\char"1D400 $}
\end{document}

@josephwright
Copy link
Member

@davidcarlisle OK, so we mark as 'report elsewhere', prod Arthur/Jonathan about XeTeX, close here as it's Not Our Fault?

@FrankMittelbach
Copy link
Member

I'm confused. Running the code @davidcarlisle showed above outputs nothing for me (other than the page number) if I use LuaTeX and it makes an error if I use XeLaTeX. And If I replace it with \Uchar the only difference is that then both engines print nothing and no error in math for XeTeX.

Outside of math both \char and \Uchar do the same in both engies and print the symbol.

@FrankMittelbach
Copy link
Member

Maybe the question here is what should be the specification of \symbol if used in math, I mean if your math has 8bit fonts then clearly specifying "1D400 doesn't get you far.

@blefloch
Copy link
Member

blefloch commented Nov 28, 2019 via email

@FrankMittelbach
Copy link
Member

@blefloch well that clearly seems to indicate that something is not quite right on the engine level, but I still wonder if we understand what should be considered "right" in the various cases.

@u-fischer
Copy link
Member

u-fischer commented Nov 28, 2019

I'm confused. Running the code @davidcarlisle showed above outputs nothing for me (other than the page number) if I use LuaTeX and it makes an error if I use XeLaTeX.

Inside math cmmi (a legacy font ) is used. This naturally has no glyph in this unicode position. luatex handles this gracefully and simply reports a missing char. Xetex errors.

Outside math, when the stix font is used, both show the correct char.

Using a legacy font in text mode

\font\test=cmr10 \test
\char"1D400

works with both engines too (with missing char messages and naturally no output).

xelatex fails only in math (and the stix font in the example is actually irrelevant):

\documentclass{article}
\begin{document}

$\char"1D400 $
\end{document}

@FrankMittelbach
Copy link
Member

I'm confused. Running the code @davidcarlisle showed above outputs nothing for me (other than the page number) if I use LuaTeX and it makes an error if I use XeLaTeX.

Inside math cmmi (a legacy font ) is used. This naturally has no glyph in this unicode position. luatex handles this gracefully and simply reports a missing char. Xetex errors.

understood that part, yes. And assuming that the math is not using a legacy font then luatex would print a char?

if so I don't quite understand why your suggestion to make \symbol use \Uchar with these engines is not and answer to the problem (which seems to be what @davidcarlisle was hinting at).

@u-fischer
Copy link
Member

u-fischer commented Nov 28, 2019

if so I don't quite understand why your suggestion to make \symbol use \Uchar with these engines is not and answer to the problem

It certainly avoids the problem, \Uchar does the right thing, also it is imho sensible anyway to use \Uchar with the unicode engines, so I don't see a problem to change \symbol to use it. But @davidcarlisle is imho right that the xetex behaviour looks like a bug, so it should be reported.

@u-fischer
Copy link
Member

And assuming that the math is not using a legacy font then luatex would print a char?

with unicode-math luatex prints a char, but xetex still errors.

\documentclass{article}
\usepackage{unicode-math}
\begin{document}
abc
$\char"1D400 $
\end{document}

@FrankMittelbach
Copy link
Member

Never really looked into the \Uchar \char specs in the Unicode engines, but do I see it right that in LuaTeX the both are 100% equiv? And that in XeTeX one could always use \Uchar instead of \char? or are there other differences? Because if not, then we could drop \char in Unicode engines by setting \let\char\Uchar, could we not?

@josephwright
Copy link
Member

\Uchar is expandable, and is getting added to pTeX ...

@davidcarlisle
Copy link
Member

davidcarlisle commented Nov 28, 2019

as it's being added to ptex, we could consider adding it to pdftex as well, but I still would say the main issue here is a xetex bug. If we make \symbol latex \protect ed but with an expandable internal definition I suppose it's more or less compatible with a \char based definition, although there would be a temptation to remove the protection so it expanded in a \typeout in that case

@zauguin
Copy link
Member

zauguin commented Nov 30, 2019

Never really looked into the \Uchar \char specs in the Unicode engines, but do I see it right that in LuaTeX the both are 100% equiv? And that in XeTeX one could always use \Uchar instead of \char? or are there other differences? Because if not, then we could drop \char in Unicode engines by setting \let\char\Uchar, could we not?

No, they aren't equivalent. Beside ``\Ucharbeing expandable another difference is that\Uchar 32` becomes a space token and therefore inserts (space) glue, while `\char 32` inserts the glyph at code point 32. (This is an artifact of `\Uchar` using the same catcode rules as other expandable primitives expanding to text) E.g.

\documentclass{article}
\begin{document}
\parfillskip 0pt
\hsize 5cm
aaa\Uchar 32 aaa

aaa\char 32 bbb
\end{document}

stretches the first line but not the second.

I think \symbol should definitly give the \char behaviour, so if this is changed to \Uchar there should be a special case for symbol 32.

@blefloch
Copy link
Member

blefloch commented Nov 30, 2019 via email

@davidcarlisle
Copy link
Member

@blefloch unless you use the l3 (or ucharcat package) Lua implementation that's not available in luatex. I think we should first try to get \char fixed in xetex.

@blefloch
Copy link
Member

blefloch commented Dec 1, 2019 via email

@stale
Copy link

stale bot commented Jan 30, 2020

This issue has been automatically marked as stale because it has not had recent activity.

@stale stale bot added the stale label Jan 30, 2020
@FrankMittelbach FrankMittelbach added this to Pool (unscheduled issues) in upcoming LaTeX2e releases via automation Feb 6, 2020
@FrankMittelbach FrankMittelbach added this to the release 2020 fall milestone Feb 6, 2020
@stale stale bot removed the stale label Feb 6, 2020
wspr added a commit that referenced this issue Feb 6, 2020
@FrankMittelbach FrankMittelbach added the fixed in dev Fixed in development branch, not in stable release label Feb 10, 2020
@FrankMittelbach FrankMittelbach moved this from Pool (unscheduled issues) to Done in dev in upcoming LaTeX2e releases Feb 10, 2020
FrankMittelbach added a commit that referenced this issue Feb 11, 2020
upcoming LaTeX2e releases automation moved this from Done in dev to Done May 28, 2020
@FrankMittelbach FrankMittelbach removed the fixed in dev Fixed in development branch, not in stable release label Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

7 participants