如何巧妙地解决不需要的空白问题?

如何巧妙地解决不需要的空白问题?

为什么左边有一个空白?

\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}

在此处输入图片描述

答案1

三个不受保护的行尾asymptote.sty(标有%<---)。

\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}

请注意,这\noindent不是必需的。

如何找到它们?我删除了\noindent不执行任何操作的standalone,将其替换为

\tracingcommands=1 \tracingmacros=1

我使用 进行编译pdflatex,运行asy并再次编译。.log文件是搜索的{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

显然,这\asy@init是负责任的,事实上它的定义是

\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}%
}

显示缺少两项%保护。

重新定义命令并重试。该死!仍然有一个空白处!

\ASYasydir ->
{blank space  }

\asy@write@graphic@header ->\immediate \openout \AsyStream =\ASYasydir \jobname

\asy@write@graphic@header在以下位置查找asymptote.sty:我们在以下定义中找到它\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}%
}

修复它并再次检查。好极了!没有空格!

相关内容