vectorgraphics / asymptote

2D & 3D TeX-Aware Vector Graphics Language
https://asymptote.sourceforge.io/
GNU General Public License v3.0
547 stars 90 forks source link

Using -inlinetex with embedded (rendered) 3D into 2D picture generates broken .tex file #285

Closed zzdatura closed 2 years ago

zzdatura commented 2 years ago

Description

When embedding a rendered 3D frame into a 2D picture, if asymptote is run with the -inlinetex option, the generated .tex file is broken as it tries to \includegraphics from a file that doesn't exist.

The \includegraphics should actually be an \input to another .tex file.

Example

Here is the example file:

// test.asy
import three;

picture pic;
size(pic, 1cm);
draw(pic, unitsphere);

size(2cm);
add(currentpicture, pic.fit(), (0.5, 0.5));
draw(unitsquare, red);

The config.asy is empty, and I run: asy -inlinetex -tex pdflatex test, which then generates files:

test+0_0.pdf
test_0.pdf
test+0.tex
test.pre
test.tex

The problem is in test.tex:

\setlength{\unitlength}{1pt}%
\makeatletter%
\let\ASYencoding\f@encoding%
\let\ASYfamily\f@family%
\let\ASYseries\f@series%
\let\ASYshape\f@shape%
\makeatother%
{\catcode`"=12%
\includegraphics{test_0}%
}%
\definecolor{ASYcolor}{gray}{0.000000}\color{ASYcolor}%
\fontsize{12.000000}{14.400000}\selectfont%
\usefont{\ASYencoding}{\ASYfamily}{\ASYseries}{\ASYshape}%
\ASYalign(-28.452756,28.452756)(-0.500000,-0.500000){\includegraphics[hiresbb]{test+0}}%

The last line tries to include test+0.pdf which doesn't exist. It should instead input test+0.tex which in turn includes test+0_0.pdf. Therefore, if I simply change that to:

\ASYalign(-28.452756,28.452756)(-0.500000,-0.500000){\input{test+0}}%

then I can use the file in another project and everything works fine.

Note that if I don't use -inlinetex, everything just works without issues. Also, if there's no 3D involved in the drawings, no problems occur and the .tex file is generated correctly.

Asymptote version

Asymptote version 2.73-7 [(C) 2004 Andy Hammerlindl, John C. Bowman, Tom Prince]

ENABLED OPTIONS:
WebGL    3D HTML rendering
OpenGL   3D OpenGL rendering
SSBO     GLSL shader storage buffer objects
GSL      GNU Scientific Library (special functions)
FFTW3    Fast Fourier transforms
XDR      external data representation (portable binary file format for V3D)
CURL     URL support
lsp      language server protocol
Readline interactive history and editing
Sigsegv  distinguish stack overflows from segmentation faults
GC       Boehm garbage collector

DISABLED OPTIONS:
johncbowman commented 2 years ago

Thank you for the clear explanation of the problem and solution. Users can wait for the 2.74 release or update three.asy now: https://raw.githubusercontent.com/vectorgraphics/asymptote/HEAD/base/three.asy