josephwright / beamer

A LaTeX class for producing presentations and slides
Other
1.44k stars 143 forks source link

Incorrect block shading with XeLaTeX #492

Closed leo-liu closed 6 years ago

leo-liu commented 6 years ago

The latest release (3.51) and dev version (82101f9cba398faa182df9a7bde80de9cd8851fb) may produce incorrect block shading with XeLaTeX.

It seems caused by pull request #469.

MWE:

\documentclass{beamer}
\usetheme{Warsaw}
\begin{document}

\begin{frame}
\begin{block}{Title}
text
\end{block}

\begin{block}{}
TEXT
\end{block}
\end{frame}

\begin{frame}
\begin{theorem}
text

text

text

text
\end{theorem}
\end{frame}

\end{document}

default

default

josephwright commented 6 years ago

I agree that the issue comes from the pull request. Looking at the code there, everything is done 'properly' using pgf interfaces: I don't think the logic in beamer is the issue. Rather, there must be something up in pgf with the operations used (or it could be (x)dvipdfmx). I'll think a little: in a way, this is 'not a beamer bug', but probably the outcome means we'll have to back out.

ghost commented 6 years ago

@josephwright Maybe related discussion: https://github.com/josephwright/beamer/issues/161

ghost commented 6 years ago

Not only xelatex is affected, also the latex->dvi->ps->pdf route, see https://tex.stackexchange.com/questions/448709/beamer-warsaw-how-to-have-a-rounded-shadow

josephwright commented 6 years ago

@samcarter8 Quite possibly. As I say, the problem is that if you look at the code, there is nothing 'low level', it's all \pgf.... So the calculations are right in beamer.

leo-liu commented 6 years ago

AFAIK, PostScript doet not support transparency. I guess that the system layer of pgf for dvipdfmx also has some issue.

Anyway, a possible workaround for beamer is to fallback to old pgf code when pdfTeX/LuaTeX is not the engine.

josephwright commented 6 years ago

@leo-liu PostScript doesn't support transparency, but PDFs out of the process can still show it (see e.g. https://tex.stackexchange.com/questions/172764/opacity-and-transparency, using PSTricks). I agree though that there are issues in pgf here.

I'm not that keen on trying to have entirely separate code paths: I'll probably back out the change for the present, and see if I can track down the underlying issue.

samcarter commented 4 years ago

@u-fischer found a way to get the transparent shadows to work with xelatex by using unique names for the shadings, some code for testing can be found in this branch:

https://github.com/samcarter/beamer/tree/resuscitating_transparent_shadows

(needs the pgf dev version due to the problem with the shifted shadows)

Risk: for each new width or height an additional shading will be created - which at one point will probably cause problems if there are too many (could not find any problems when testing with a couple of thousand randomly sized boxes, no idea how far this will work)

@josephwright @louisstuart96 What do you think? Is this too risky? Otherwise one could also have this as a new box type, transparentshadowbox or something ...

Note to self: test file document.txt

dbitouze commented 4 years ago

@samcarter Would this code fix the issue noticed in the comment of https://tex.stackexchange.com/a/448720/18401?

(Sorry, I cannot test myself because I currently cannot test the pgf dev version.)

samcarter commented 4 years ago

@samcarter Would this code fix the issue noticed in the comment of https://tex.stackexchange.com/a/448720/18401?

This will work for the upcoming pgf version (the one currently distributed in texlive has an issue with the offset of shadings)

u-fischer commented 4 years ago

@dbitouze you need from the pgf-dev actually only this redefinition (and only if you use xelatex/xdvipdfmx):

\makeatletter

\def\pgfutil@insertatbegincurrentpagefrombox#1{%
  \edef\pgf@temp{\the\wd\pgfutil@abb}%
  \global\setbox\pgfutil@abb\hbox{%
    \unhbox\pgfutil@abb%
    \hskip\dimexpr2in-2\hoffset-\pgf@temp\relax% changed
    #1%
    \hskip\dimexpr-2in-2\hoffset\relax% new
  }%
}
dbitouze commented 4 years ago

@u-fischer And what about LuaLaTeX?

dbitouze commented 4 years ago

@u-fischer and @samcarter This redefinition doesn't fix the issue noticed in the comment of https://tex.stackexchange.com/a/448720/18401, both with xelatex and lualatex (not sure whether I should open a separate issue or not):

\documentclass{beamer}
\usepackage{pgf}

% add a background image
\setbeamertemplate{background canvas}{\includegraphics[height=\paperheight]{example-image}}

% use rounded blocks with shadow
\setbeamertemplate{blocks}[rounded][shadow=true]

\makeatletter
\def\pgfutil@insertatbegincurrentpagefrombox#1{%
  \edef\pgf@temp{\the\wd\pgfutil@abb}%
  \global\setbox\pgfutil@abb\hbox{%
    \unhbox\pgfutil@abb%
    \hskip\dimexpr2in-2\hoffset-\pgf@temp\relax% changed
    #1%
    \hskip\dimexpr-2in-2\hoffset\relax% new
  }%
}
\makeatother

\begin{document}
\begin{frame}
  \frametitle{Block with shadow and with background image}

  \begin{block}{Block with shadow}
    Content...
  \end{block}
\end{frame}
\end{document}

test

u-fischer commented 4 years ago

@dbitouze no, this fix is for displaced shadings, to correct the transparent shadow you need the code @samcarter is just including into beamer.

samcarter commented 4 years ago

@dbitouze Works fine for me with the beamer branch I linked to

Screen Shot 2020-10-19 at 17 30 00

samcarter commented 4 years ago

@u-fischer And what about LuaLaTeX?

there was no problem with shadows in lualatex

dbitouze commented 4 years ago

@dbitouze Works fine for me with the beamer branch I linked to

Ooops, sorry.

there was no problem with shadows in lualatex

I guess you mean for displaced shadings, not for correct transparent shadow (the MCE I provided above points out a problem for transparent shadow with lualatex as well).

samcarter commented 4 years ago

I guess you mean for displaced shadings, not for correct transparent shadow (the MCE I provided above points out a problem for transparent shadow with lualatex as well).

Transparent shadows did work in lualatex, but because the code did not work in xelatex, it had to be replaced with the white shadows

dbitouze commented 4 years ago

Transparent shadows did work in lualatex, but because the code did not work in xelatex, it had to be replaced with the white shadows

Too bad! It would have been nice to make use of iftex package and \ifxetex...\fi in order to affect only xe(la)tex.

samcarter commented 4 years ago

@josephwright @louisstuart96 Now that the new pgf version is available, any opinions on https://github.com/josephwright/beamer/compare/master...samcarter:resuscitating_transparent_shadows ? Take the chance and merge this into beamer? Or add it as a new transparent shadows outer theme?

josephwright commented 4 years ago

@samcarter I think we risk it and if necessary roll-back.

samcarter commented 4 years ago

@josephwright Great! I'll push the necessary chances