9

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}

enter image description here

2
  • @chishimotoji: You must contact the package author to remove the white spaces. Dec 17, 2018 at 8:35
  • @ArtificialStupidity I filed a bug report to one of the maintainers.
    – egreg
    Dec 17, 2018 at 8:37

1 Answer 1

10

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\[email protected]}{}{}%
  }%<---
  \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\[email protected]}{}{}%
  }
  \asy@write@graphic@header
  \let\ThisAsymptote\WriteAsyLine
  \ProcessAsymptote{asy}%
}

Fix it and check again. Hurray! No spaces!

5
  • (+1) This nice fix should go into asymptote.sty soon! Thanks @egreg.
    – AboAmmar
    Dec 17, 2018 at 14:40
  • 1
    I believe this really shows how horrible LaTeX programming is... How can anybody conceive a language in which comments influence the execution?!
    – Federico
    Dec 17, 2018 at 17:05
  • @Federico It's one of the reasons why expl3 was born. On the other hand, TeX is a typesetting program, so spaces cannot generally be ignored.
    – egreg
    Dec 17, 2018 at 18:17
  • 1
    @egreg Good to know about 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, 2018 at 18:22
  • @egreg Many thanks I sent a mail to the authors, it is fixed.
    – O.G.
    Dec 29, 2018 at 19:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .