# Unexpected outputs from standalone class with preview and crop options

I am designing a logo composed of two letters and am using the standalone class. I would expect the newer crop option to give me a "tighter" PDF output than the older preview option, but the reverse seems to be the case. Here is my MWE:

\documentclass[crop=true]{standalone}
\usepackage{fontspec}
\usepackage{xcolor}
\setmainfont{Noto Serif}
\setlength{\fboxrule}{0em}
\setlength{\fboxsep}{0em}
\begin{document}
\newbox{\Rx}
\newbox{\CRx}
\sbox{\Rx}{%
\fontsize{42pt}{50pt}\selectfont%
{R\hspace{-0.18em}{\raisebox{-0.22em}{\textcolor{gray}{x}}}}%
}
\fcolorbox{black}{lightgray}{\centering\usebox{\Rx}}
\end{document}


The result of the crop option is

Whereas, if I replace the class option to be previewI get the tighter PDF whose screenshot is

Why is there white space on the left of the crop image and how might it be avoided?

Thanks.

• Both standalone options preview and crop are for cropping. The first one uses the preview package internal for that (which allows for paragraph content), the latter own code (which does not allow for paragraph content, and might swallow leading and trailing spaces). – Martin Scharrer Feb 5 '20 at 14:04
• Thanks for the explanation @Martin Scharrer. The behaviour I have seen is now comprehensible. – chandra Feb 6 '20 at 15:39

You have spurious spaces in your code:

\documentclass[crop=true]{standalone}
\usepackage{fontspec}
\usepackage{xcolor}
\setmainfont{Noto Serif}
\setlength{\fboxrule}{0em}
\setlength{\fboxsep}{0em}
\begin{document}
\newbox{\Rx}% <---
\newbox{\CRx}% <---
\sbox{\Rx}{%
\fontsize{42pt}{50pt}\selectfont%
{R\hspace{-0.18em}{\raisebox{-0.22em}{\textcolor{gray}{x}}}}%
}% <---
\fcolorbox{black}{lightgray}{\centering\usebox{\Rx}}
\end{document}

• Thank you for pointing this out. I was hitherto unaware that a newline separating two one-line commands, or the newline at the terminus of a multi-line command, could both lead to a spurious space, and thus to unexpected results. – chandra Dec 31 '19 at 16:21
• Well you get a space if you type normal text on two lines, which should it be different if there are commands? – Ulrike Fischer Dec 31 '19 at 16:25
• I was not aware of that either. I tried out what you said and see that the newlines got translated into spaces in LaTeX. I need to pay more attention to terminal whitespace henceforth, including newlines. – chandra Dec 31 '19 at 16:49