无法在 Asymptote 中绘制两幅图

无法在 Asymptote 中绘制两幅图

由于某种原因,我无法在 Asymptote 中的当前图片上绘制两张图片。目前我有

\documentclass{article}

\usepackage[inline]{asymptote}

\begin{document}

\begin{asy}[width=0.7\textwidth]
import three;

string d = "$";

triple A = (0,0,0); // Vertices of a cube
triple B = (0,1,0);
triple C = (-1,1,0);
triple D = (-1,0,0);

transform3 sd = shift(0,0,-1);

triple Ap = sd * A;
triple Bp = sd * B;
triple Cp = sd * C;
triple Dp = sd * D;

void drawCube(picture pic, string[] labels) {
    draw(pic,A--B--C--Cp--Bp--Ap--A--B--Bp);
    draw(pic,B--C);
    draw(pic,A--D--C);
    draw(pic,Ap--Dp--D,dashed); // behind the cube
    draw(pic,Dp--Cp,dashed);

    if (labels.length > 0) {
        label(pic, d + labels[0] + d, A, NW);
        label(pic, d + labels[1] + d, B, N);
        label(pic, d + labels[2] + d, C, NE);
        label(pic, d + labels[3] + d, D, N);
        label(pic, d + labels[4] + d, Ap, SW);
        label(pic, d + labels[5] + d, Bp, S);
        label(pic, d + labels[6] + d, Cp, SE);
        label(pic, d + labels[7] + d, Dp, S);
    }
}

picture start; // first picture (the one with the cube)
size(start, 100);

string[] start_labels = {"A","B","C","D","A'","B'","C'","D'"};
drawCube(start, start_labels);

picture step1; // second figure, the one with the dashed line
size(step1, 100);

triple corner1 = (0,0,0);
triple corner2 = (-1,1,-1);

draw(step1, corner1--corner2,dashed);
dot(step1, corner1);
dot(step1, corner2);

add(step1.fit(), (-2,0), N); // LINE 1
add(start.fit(), (0,0), N); // LINE 2

label("Starting position", (0,0),S);
label("Choose a pair of vertices: $2$ ways", (-2,0), S);

\end{asy}

\end{document}

如果这是文件“test.tex”,那么构建脚本文件就是

pdflatex test.tex
asy *.asy
pdflatex test.tex
pdflatex test.tex

我希望有一个图形,左边是虚线,右边是立方体。但是,当我在这个文件上运行 Asymptote 时,我得到了两个立方体!

两个并排的立方体

我尝试交换标有“LINE 1”和“LINE 2”的线条,结果另一张图片被绘制了两次:

两条线并排

显然,这非常令人沮丧。如何解决此问题?

编辑:这是用 pdflatex 编译的,它会在同一目录中输出一个 .asy 文件,然后用 asy 编译。除了一些不影响它的 asydef 代码和添加到开头的以下内容外,文件是相同的:

if(!settings.multipleView) settings.batchView=false;
settings.tex="pdflatex";
settings.inlinetex=true;
deletepreamble();
defaultfilename="test-1";
if(settings.render < 0) settings.render=4;
settings.outformat="";
settings.inlineimage=true;
settings.embed=true;
settings.toolbar=false;
viewportmargin=(2,2);

另外,最后还有这一行:

size(241.49895pt,0,keepAspect=true);

答案1

我很乐意删除它,但也许它有帮助。我无法编译你的文件,但当我使用该asypictureB包时,它有一个额外的优势,即只需要运行pdflatex -shell-escape <file>(而不需要单独的asy),

\documentclass{article}
\usepackage{asypictureB}
\begin{document}

\begin{asypicture}{name=Ovinus}
import three;

string d = "$";

triple A = (0,0,0); // Vertices of a cube
triple B = (0,1,0);
triple C = (-1,1,0);
triple D = (-1,0,0);

transform3 sd = shift(0,0,-1);

triple Ap = sd * A;
triple Bp = sd * B;
triple Cp = sd * C;
triple Dp = sd * D;

void drawCube(picture pic, string[] labels) {
    draw(pic,A--B--C--Cp--Bp--Ap--A--B--Bp);
    draw(pic,B--C);
    draw(pic,A--D--C);
    draw(pic,Ap--Dp--D,dashed); // behind the cube
    draw(pic,Dp--Cp,dashed);

    if (labels.length > 0) {
        label(pic, d + labels[0] + d, A, NW);
        label(pic, d + labels[1] + d, B, N);
        label(pic, d + labels[2] + d, C, NE);
        label(pic, d + labels[3] + d, D, N);
        label(pic, d + labels[4] + d, Ap, SW);
        label(pic, d + labels[5] + d, Bp, S);
        label(pic, d + labels[6] + d, Cp, SE);
        label(pic, d + labels[7] + d, Dp, S);
    }
}

picture start; // first picture (the one with the cube)
size(start, 100);

string[] start_labels = {"A","B","C","D","A'","B'","C'","D'"};
drawCube(start, start_labels);

picture step1; // second figure, the one with the dashed line
size(step1, 100);

triple corner1 = (0,0,0);
triple corner2 = (-1,1,-1);

draw(step1, corner1--corner2,dashed);
dot(step1, corner1);
dot(step1, corner2);

add(step1.fit(), (-2,0), N); // LINE 1
add(start.fit(), (0,0), N); // LINE 2

label("Starting position", (0,0),S);
label("Choose a pair of vertices: $2$ ways", (-2,0), S);

\end{asypicture}

\end{document}

我明白了

在此处输入图片描述

我知道不应该有重叠的文本,但至少不会出现您提到的问题。

相关内容