Why is there a white space on the left side?
\documentclass{standalone}
\usepackage{asymptote}
\begin{document}
\noindent
\begin{asy}
size(10cm,10cm);
draw((0,0)--(100,100));
draw((0,100)--(100,0));
dot((50,50));
\end{asy}
\end{document}
Why is there a white space on the left side?
\documentclass{standalone}
\usepackage{asymptote}
\begin{document}
\noindent
\begin{asy}
size(10cm,10cm);
draw((0,0)--(100,100));
draw((0,100)--(100,0));
dot((50,50));
\end{asy}
\end{document}
Three unprotected end-of-lines in asymptote.sty (marked with %<---).
\documentclass{standalone}
\usepackage{asymptote}
\makeatletter
\def\asy@init{%<---
\def\ASYlatexdir{}%<---
\ifx\asylatexdir\empty\else
\def\ASYlatexdir{\asylatexdir/}%
\fi
\ifx\asydir\empty\else
\def\ASYasydir{\asydir/}%
\fi
\def\ASYprefix{\ASYlatexdir\ASYasydir}%
}
\renewcommand\asy[1][]{%
\stepcounter{asy}%
\setkeys{ASYkeys}{#1}%
\ifASYattach
\ASYinlinefalse
\fi
\asy@init
\immediate\write\AsyPreStream{%
\noexpand\InputIfFileExists{%
\ASYprefix\noexpand\jobname-\the\c@asy.pre}{}{}%
}%<---
\asy@write@graphic@header
\let\ThisAsymptote\WriteAsyLine
\ProcessAsymptote{asy}%
}
\makeatother
\begin{document}
\begin{asy}
size(10cm,10cm);
draw((0,0)--(100,100));
draw((0,100)--(100,0));
dot((50,50));
\end{asy}
\end{document}
Note that \noindent is not necessary.
How to find them? I removed \noindent that does nothing with standalone, replacing it with
\tracingcommands=1 \tracingmacros=1
I compiled with pdflatex, ran asy and compiled again. The .log file is the searched for {blank space}:
\asy@init -> \def \ASYlatexdir {} \ifx \asylatexdir \empty \else \def \ASYlatex
dir {\asylatexdir /}\fi \ifx \asydir \empty \else \def \ASYasydir {\asydir /}\f
i \def \ASYprefix {\ASYlatexdir \ASYasydir }
{blank space }
{\def}
{blank space }
{\def}
{\immediate}
\ASYprefix ->\ASYlatexdir \ASYasydir
\ASYlatexdir ->
\ASYasydir ->
{blank space }
\asy@write@graphic@header ->\immediate \openout \AsyStream =\ASYasydir \jobname
It is apparent that \asy@init is responsible and indeed its definition is
\def\asy@init{
\def\ASYlatexdir{}
\ifx\asylatexdir\empty\else
\def\ASYlatexdir{\asylatexdir/}%
\fi
\ifx\asydir\empty\else
\def\ASYasydir{\asydir/}%
\fi
\def\ASYprefix{\ASYlatexdir\ASYasydir}%
}
showing two missing % protections.
Redefine the command and retry. Darn! There's still a blank space!
\ASYasydir ->
{blank space }
\asy@write@graphic@header ->\immediate \openout \AsyStream =\ASYasydir \jobname
Look for \asy@write@graphic@header in asymptote.sty: we find it in the definition of \asy:
\newcommand\asy[1][]{%
\stepcounter{asy}%
\setkeys{ASYkeys}{#1}%
\ifASYattach
\ASYinlinefalse
\fi
\asy@init
\immediate\write\AsyPreStream{%
\noexpand\InputIfFileExists{%
\ASYprefix\noexpand\jobname-\the\c@asy.pre}{}{}%
}
\asy@write@graphic@header
\let\ThisAsymptote\WriteAsyLine
\ProcessAsymptote{asy}%
}
Fix it and check again. Hurray! No spaces!
expl3 was born. On the other hand, TeX is a typesetting program, so spaces cannot generally be ignored.
– egreg
Dec 17 '18 at 18:17
expl3; I'll have a look. "TeX is a typesetting program, so spaces cannot generally be ignored": that is just a severely bad separation of concerns in the TeX system, where there is no distinction between "typing mode" and "programming mode".
– Federico
Dec 17 '18 at 18:22