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

xetex: wrong position of node current page #909

Closed
muzimuzhi opened this issue Aug 18, 2020 · 4 comments · Fixed by #916
Closed

xetex: wrong position of node current page #909

muzimuzhi opened this issue Aug 18, 2020 · 4 comments · Fixed by #916

Comments

@muzimuzhi
Copy link
Member

Brief outline of the bug

From question https://tex.stackexchange.com/q/559138/79060.

Compiled with xetex, the position of node current page is wrongly calculated if \hoffset and/or \voffset are/is non-zero.

Minimal working example (MWE)

\documentclass{article}
\usepackage{tikz}

\usepackage[papersize={6cm, 8cm}]{geometry}
\hoffset=15pt
\voffset=15pt

\begin{document}
\begin{tikzpicture}[remember picture, overlay]
  \draw[line width=10pt, blue, double=blue!50, double distance=10pt] 
    (current page.north west) rectangle (current page.south east);
\end{tikzpicture}
\end{document}

Expected output: with pdftex or luatex
image

Actual output: with xetex
image

@muzimuzhi
Copy link
Member Author

muzimuzhi commented Aug 18, 2020

Proposal

diff --git a/tex/generic/pgf/systemlayer/pgfsys-xetex.def b/tex/generic/pgf/systemlayer/pgfsys-xetex.def
index e191b9da..9eb1d23d 100644
--- a/tex/generic/pgf/systemlayer/pgfsys-xetex.def
+++ b/tex/generic/pgf/systemlayer/pgfsys-xetex.def
@@ -62,7 +62,7 @@
   \pgf@marshal%
 }

-\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{2\hoffset}{0pt}}
+\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{\hoffset}{\voffset}}

 \ifx\paperheight\@undefined
 \else

The last modification to related line is done by cdacb87 in 2013, in order to fix #85.

Edit: I'm not familiar with either the system layer of pgf or xetex specific things, but an asymmetric use of \hoffset and \voffset is really wired and since the definitions of \pgf@sys@pdf@mark@pos@pgfpageorigin in every other pgfsys-xxx.def are symmetric ...

./pgfsys-common-pdf-via-dvi.def:110:  \def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfpointorigin}
./pgfsys-dvips.def:158:\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfpointorigin}
./pgfsys-pdftex.def:266:\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{\hoffset}{\voffset}}
./pgfsys-xetex.def:65:\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{2\hoffset}{0pt}}
./pgfsys-dvipdfmx.def:250:  \def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfpointorigin}
./pgfsys-dvisvgm.def:207:\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfpointorigin}
./pgfsys-luatex.def:269:\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{\hoffset}{\voffset}}

@hmenke
Copy link
Member

hmenke commented Aug 18, 2020

Exact duplicate of #294
Please search existing issues before opening a new one.

@muzimuzhi
Copy link
Member Author

muzimuzhi commented Aug 19, 2020

Exact duplicate of #294

Not exactly the same.

#294 reported a problem reproducible with every engine, while this issue reports a problem specific to xetex, which corresponds to a bug fix [1] of xetex introduced in texlive 2020. The above proposed change for pgfsys-xetex.def actually restores the buggy level of xetex to #294, but it will not and has no intent to fix #294.

[1] About this bug:

Therefore the whole story is:

  1. there was a long-standing xetex bug (not newer than xetex 0.999991)
  2. pgf used some workaround to live with that bug
  3. now the bug is fixed (since xetex 0.999992)
  4. pgf need to take a corresponding change

A refined proposal would be

diff --git a/tex/generic/pgf/systemlayer/pgfsys-xetex.def b/tex/generic/pgf/systemlayer/pgfsys-xetex.def
index e191b9da..4cdaf9ab 100644
--- a/tex/generic/pgf/systemlayer/pgfsys-xetex.def
+++ b/tex/generic/pgf/systemlayer/pgfsys-xetex.def
@@ -62,7 +62,14 @@
   \pgf@marshal%
 }

-\def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{2\hoffset}{0pt}}
+% this test fails if xetex releases 1.0 in the future
+\ifnum\expandafter\pgfutil@gobble\XeTeXrevision>999991\relax
+  \def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{\hoffset}{\voffset}}
+\else
+  \def\pgf@sys@pdf@mark@pos@pgfpageorigin{\pgfqpoint{2\hoffset}{0pt}}
+\fi

 \ifx\paperheight\@undefined
 \else

Sorry I was obviously in a hurry yesterday. The #294 you mentioned let me learn more.


To be more specific, using the example given in #294 (comment),

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}

\advance\hoffset by 4cm

\begin{document}
\tikz[overlay,remember picture]
  \draw[green,<->] (current page.south west) --  (current page.north east);%

abc
\end{document}
  • With texlive 2019 (for example using overleaf), each one of pdftex, xetex, and luatex gives the same shifted output.
  • With texlive 2020, output of pdftex and luatex are unchanged, but output of xetex now has the shifting amount doubled.
    imageimage

@hmenke
Copy link
Member

hmenke commented Sep 3, 2020

Can you make a PR with that patch?

muzimuzhi added a commit to muzimuzhi/pgf that referenced this issue Sep 3, 2020
There was a "\pdfsavepos" bug in XeTeX
    https://sourceforge.net/p/xetex/bugs/56/
which caused the asymmetric workaround "\pgfqpoint{2\hoffset}{0pt}"
in defining node "current page". XeTeX has fixed the bug in 0.999992
hence now pgf can use a normal symmetric
"\pgfqpoint{\hoffset}{\voffset}" now.
muzimuzhi added a commit to muzimuzhi/pgf that referenced this issue Sep 3, 2020
There was a "\pdfsavepos" bug in XeTeX
    https://sourceforge.net/p/xetex/bugs/56/
which caused the asymmetric workaround "\pgfqpoint{2\hoffset}{0pt}"
in defining node "current page". XeTeX has fixed the bug in 0.999992
hence now pgf can use a normal symmetric
"\pgfqpoint{\hoffset}{\voffset}".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants