0

I'm compiling this code with XeLaTeX:

\documentclass[11pt]{article}
\usepackage{graphicx}
\begin{document}
    This text is blurry if there is an image.
    \includegraphics{Test.png}
\end{document}

where the image I'm including is:
Image

If I comment out the \includesgraphics, I get:

Clear

If I don't, I get:

Blurry

Why does the text look different (in my eyes, blurrier) when there is an image on the screen?
How can I prevent this from happening in XeLaTeX?

user541686
  • 9,547
  • 2
    The PNG file contains an alpha channel for transparency. Remove this channel with the image manipulation software of your choice. Actually this effect shouldn't occur anymore but seems to depend on the used PDF viewer. – Thorsten Donig Sep 22 '13 at 19:58
  • @ThorstenDonig: I just tried that, and it didn't help. But even if it had, I wouldn't want to remove the alpha channel... – user541686 Sep 22 '13 at 20:02
  • @ThorstenDonig: Also I'm not sure what you mean by it "shouldn't occur anymore"... I have a recent version of Acrobat (10) and a recent version of MiKTeX (2.9) so it's not because I'm using old software... – user541686 Sep 22 '13 at 20:10
  • @JosephWright: No, they're arbitrary PNGs. Honestly, I'm not trying to figure out how to draw vectors in LaTeX, I'm not trying to find the right Unicode character for a star... it's not that complicated :) I'm trying to figure out how to prevent the includion of an arbitrary image from making the text look different. – user541686 Sep 22 '13 at 21:22
  • @Mehrdad Which viewers/platforms did you try? XeLaTeX, along with other TeX engines, more-or-less just copies images directly into the output. As such, problems with the appearance of PDFs often come down to the viewer(s) involved. – Joseph Wright Sep 22 '13 at 21:23
  • @JosephWright: Huh? It's perfectly possible for a PDF with an image to not look like this in Acrobat, so I don't see how it could be a viewer issue. XeLaTeX is doing something to the output that it shouldn't be doing, so if it's rendering incorrectly in Acrobat that's XeLaTeX's fault, not Acrobat's. I shouldn't have to make the reader use a different PDF viewer just because XeLaTeX is giving bad output. Regardless, I already answered that a couple comments ago -- I'm using Acrobat 10 (on Windows). – user541686 Sep 22 '13 at 21:24
  • @Mehrdad Unfortunately, some issues/'features' in viewers only show up under particular circumstances. In the case here, if images in general broke/degraded output then there would be a serious problem for XeTeX users. For me if I download your image and run the test with XeLaTeX then all is well with the viewers I've tried (TeXworks and Preview on my Mac, with an up-to-date TeX Live, TeXworks on Windows 7 with an up-to-date MiKTeX 2.9). – Joseph Wright Sep 22 '13 at 21:31
  • @JosephWright: Two things worth mentioning: (1) 2D graphics acceleration probably isn't enabled on your computer in Acrobat, that's probably why. (2) The output looks just fine if I use PDFLaTeX, this only happens on XeTeX. – user541686 Sep 22 '13 at 21:36
  • @Mehrdad That is very strange since using the second image leads no boldness whereas using the first image does here with XeLaTeX. Therefore we certainly need more details on this. – yo' Sep 22 '13 at 21:37
  • @tohecz: Sure, what kind of more details do you need? – user541686 Sep 22 '13 at 21:38
  • @Mehrdad Might be useful if you could upload the PDFs (with transparency and without) somewhere we can download and test. Also I guess exact version numbers (XeTeX and Adobe Reader). EDIT: The PDFs will of course have the XeTeX stuff in as a banner, so ignore that! – Joseph Wright Sep 22 '13 at 21:40
  • @Mehrdad That's difficult to say. Maybe if you upload the PDF file somewhere so that we can check where the behaviour occurs? – yo' Sep 22 '13 at 21:40
  • @tohecz: Okay let me try making a PDF again... – user541686 Sep 22 '13 at 21:41
  • @tohecz: I just realized there is some funny behavior going on -- I made the PNG transparent using Photoshop's "Save for Web" feature, but when I'm trying to reproduce what I saw, I now see the image is blurred (scaled??) in that case, whereas the text is fine... the original is here. No idea what's happening... – user541686 Sep 22 '13 at 21:57
  • @Mehrdad Try the recommended convert from ImageMagick, that might help ;) – yo' Sep 22 '13 at 21:58
  • @tohecz: To remove the alpha channel you mean? But I don't want to remove the transparency from every image... I need them in some cases. Are you saying it's impossible without removing the transparency? – user541686 Sep 22 '13 at 21:59
  • @Mehrdad Yes, exactly that. If there had been a better solution, someone would have pointed it out before. This is a problem that quite affects pdflatex too, although it seems that the last version brings some improvements, so it is possible that in some time, xelatex will get better, too. But then it is more a "feature request" than a question suitable for an SE site. Currently, the only answer is really to get rid of transparency, or get rid of Acrobat. – yo' Sep 22 '13 at 22:37
  • @tohecz: I see... would you mind posting this comment as an answer then? I'd accept it, thanks. – user541686 Sep 22 '13 at 22:37
  • @Mehrdad I don't think I'm going to do so since that is basically what http://tex.stackexchange.com/a/172/11002 says. IMHO this is just a duplicate. – yo' Sep 22 '13 at 22:40
  • @tohecz: Okay that's fine, I'll just let it get marked as a duplicate then. I didn't realize this was the only solution since the other answer said removing transparency is the "simplest" solution... :\ – user541686 Sep 22 '13 at 22:40

1 Answers1

6

There is no need to use a bitmap image for the symbol. It is the Unicode character ☆:

U+2606 WHITE STAR

LuaTeX

Even with bold fonts, the symbol does not have the thickness of the lines usually. This can be manipulated by package pdfrender that works for pdfTeX/LuaTeX in PDF mode. Example:

\documentclass{article}
\usepackage{fontspec}
\usepackage{pdfrender}

\newcommand*{\mysymbfont}{%
  \fontspec{\myfont}%
  \fontsize{5em}{5em}\selectfont
}
\newcommand*{\textbigwhitestar}{^^^^2606}

\begin{document}
  \tabcolsep=.2\tabcolsep
  \begin{tabular}{llll}
    \xdef\myfont{DejaVuSans-Bold.ttf}%
      \texttt{\myfont}:
    &
      \mysymbfont
      \textbigwhitestar
    & \mysymbfont
      \textpdfrender{
        TextRenderingMode=Stroke,
        LineJoinStyle=Round,
        LineWidth=.5pt,
      }{\textbigwhitestar}
    & \mysymbfont
      \textpdfrender{
        TextRenderingMode=FillStroke,
        LineJoinStyle=Round,
        LineWidth=2pt,
      }{\textbigwhitestar}
    \\
    \xdef\myfont{xits-math.otf}%
      \texttt{\myfont}:
    & \mysymbfont
      \textbigwhitestar
    & \mysymbfont
      \textpdfrender{
        TextRenderingMode=Stroke,
        LineJoinStyle=Round,
        LineWidth=.5pt,
      }{\textbigwhitestar}
    & \mysymbfont
      \textpdfrender{
        TextRenderingMode=FillStroke,
        LineJoinStyle=Round,
        LineWidth=1pt,
      }{\textbigwhitestar}
  \end{tabular}
\end{document}

Result

XeTeX

In XeTeX the symbol can be included as PDF file, generated via LuaTeX, e.g.:

% whitestar-raw.tex for LuaLaTeX
\documentclass{article}
\usepackage{fontspec}
\usepackage{pdfrender}
\pagestyle{empty}

\begin{document}
  \fontspec{DejaVuSans-Bold.ttf}
  \fontsize{5em}{5em}\selectfont
  \textpdfrender{
    TextRenderingMode=FillStroke,
    LineJoinStyle=Round,
    LineWidth=2pt,
  }{^^^^2606}
\end{document}

Then compile it and crop the margins:

lualatex whitestar-raw
pdfcrop whitestar-raw.pdf whitestar.pdf

whitestar

In XeTeX the PDF file is included via:

\includegraphics{whitestar}
Moriambar
  • 11,466
Heiko Oberdiek
  • 271,626
  • 2
    Summarising removed comments: The question is about a general problem, in that adding images such as the example given results in 'blurry' text. As such, this answer doesn't address the key problem for the questionner, as the star was only an example. – Joseph Wright Sep 23 '13 at 07:21