4

I find that Adobe Acrobat (on Windows 11 and on Android) does not correctly render transparency produced via transparent.sty and PDFLaTeX. Specifically, overlapping text comes out as a uniform gray.

Here's an example:

\documentclass{article}
\usepackage{transparent}
\begin{document}
\vbox{%
  \hbox{\texttransparent{0.5}{hello}}%
  \vskip-\baselineskip
  \hbox{\texttransparent{0.5}{world}}%
}%
\end{document}

Acrobat screenshot:

Acrobat screenshot

Chrome screenshot (similar in most other PDF viewers I've tried):

Chrome screenshot

I want to achieve the latter behavior, where overlapping text appears darker. Maybe Acrobat is using the wrong blend mode for transparency? (It does seem to blend properly with a background \pagecolor.) Is there a way to fix this? Perhaps one of the other ways to specify transparency in LaTeX would do better?

edemaine
  • 263
  • I just found a relevant past post: https://tex.stackexchange.com/questions/565281/luatex-pdftex-incorrect-transparency-for-fonts-with-overlapping-glyphs-achie I'm going to see if I can get \begin{transparencygroup} working for my purposes... Oops, that's LuaTeX only I guess. I'd like to avoid the overhead of TikZ if possible. – edemaine Mar 30 '23 at 16:06
  • 1
    General comment, slightly off-topic, but worth knowing: The issue raised in this question is one reason why most "print on demand" (to paper) services disallow vector artwork, transparency, and overlaps. Not specific to TeX. Rather, different software (such as the printer's firmware) may render differently. – rallg Mar 30 '23 at 19:09

3 Answers3

5

By default, Acrobat treats text in the same text object as if it were in a knockout transparency group, leading to the observed behavior. This is a configurable graphic state parameter (TK for "text knockout") which you can turn off:

\DocumentMetadata{}
\documentclass{article}
\usepackage{iftex, transparent}

\ExplSyntaxOn \pdfmanagement_add:nnn { Page / Resources / ExtGState } { no.text.knockout } { << /TK~false >> } \ExplSyntaxOff

\ifpdftex \newcommand \disabletextknockout {% \pdfliteral page {/no.text.knockout gs}% } \else \RequireLuaTeX \newcommand \disabletextknockout {% \pdfextension literal page {/no.text.knockout gs}% } \fi \begin{document} \disabletextknockout \vbox{% \hbox{\texttransparent{0.5}{hello}}% \vskip-\baselineskip \hbox{\texttransparent{0.5}{world}}% }% \end{document}

Ulrike Fischer
  • 327,261
  • Wow, that sounds amazing! I couldn't actually get your example to run; my pdflatex(TeX Live 2023/Cygwin) complains that \pdfextension isn't defined. Is \pdfextension supposed to be available in pdflatex or just luatex? Also, for us LaTeX2e luddites, is there an analog to \pdfmanagement_add:nnn or do I need to evolve to expl3? – edemaine Mar 31 '23 at 19:45
  • 1
    Oh, I missed that you still use pdfLaTeX. Just replace \pdfextension literal with \pdfliteral. I don't think there's another name for pdfmanagement_add:nnn, but you can reduce the ExplSyntax block by defining an alias usable outside of it. – Marcel Krüger Apr 01 '23 at 09:17
  • Thanks, it works great now! Finally time to learn expl3 I guess. :-) – edemaine Apr 01 '23 at 20:44
3

You could use tikz. It puts the text inside an XObjects, and adobe handles that slightly differently to text which is directly in the stream. (It is probably possible to get a similar effect with transparent at the page group level, but the description in the pdf reference is rather long and I don't have the time to figure out which setting is needed).

\documentclass{article}
\usepackage{tikz}

\begin{document} \tikz { \node[black,opacity=0.5] {hello}; \node[black,opacity=0.5] {world}; } \end{document}

enter image description here

Ulrike Fischer
  • 327,261
0

In my setting, I wanted to use the same box logic but only have a different implementation of \texttransparent (to replace transparent.sty). I found the following PGF-based solution, based on https://tex.stackexchange.com/a/565470/245104, to work well:

\documentclass{article}
\usepackage{pgf}

\newcommand\textopacity[2]{% \begin{pgfpicture}% \pgfsetfillopacity{#1}% \pgfpathmoveto{\pgfpointorigin}% \pgftext[base]{#2}% \end{pgfpicture}% }

\begin{document} \vbox{% \hbox{\textopacity{0.5}{hello}}% \vskip-\baselineskip \hbox{\textopacity{0.5}{world}}% }% \end{document}

Acrobat screenshot:

Acrobat screenshot

I'd still prefer a solution that doesn't rely on PGF. I tried figuring out how PGF maps to PDF XObjects via \pdfxform but my attempts failed.

edemaine
  • 263