0

I have been using Asymptote to make pictures that can be included in Latex documents. I recently discovered that Org mode plays well with Asymptote

https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-asymptote.html#orgbded9e5

I was able to successfully compile a Latex document with embedded Asymptote code as follows.

#+TITLE: Test Document
#+AUTHOR: A. U. Thor
#+latex_class_options: [10pt]
#+LATEX_HEADER: \usepackage[margin=0.5in]{geometry}            
#+LATEX_HEADER: \usepackage{parskip} 
#+LATEX_HEADER: \usepackage{graphicx}                         
#+LATEX_HEADER: \usepackage{asymptote}
#+OPTIONS:      toc:nil 



#+BEGIN_SRC asymptote :file test.pdf
include graph;
size(1inch);
filldraw(circle((0,0),1),yellow,black);
fill(circle((-.3,.4),.1),black);
fill(circle((.3,.4),.1),black);
draw(arc((0,0),.5,-140,-40));
#+END_SRC

This generates the document as in the screenshot below. enter image description here

How can I adjust the instructions in the header of the code-chunk above, to be able to manipulate the size and placement (left/right/center) of the image? Right now the image is just too big.

Note: If it helps, the generated \LaTeX source file, exported from the Org file looks like this

% Created 2019-04-13 Sat 15:26
% Intended LaTeX compiler: pdflatex
\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{grffile}
\usepackage{longtable}
\usepackage{wrapfig}
\usepackage{rotating}
\usepackage[normalem]{ulem}
\usepackage{amsmath}
\usepackage{textcomp}
\usepackage{amssymb}
\usepackage{capt-of}
\usepackage{hyperref}
\usepackage{minted}
\usepackage[margin=0.5in]{geometry}
\usepackage{parskip}
\usepackage{graphicx}
\usepackage{asymptote}
\author{A. U. Thor}
\date{\today}
\title{Test Document}
\hypersetup{
 pdfauthor={A. U. Thor},
 pdftitle={Test Document},
 pdfkeywords={},
 pdfsubject={},
 pdfcreator={Emacs 26.1 (Org mode 9.1.9)}, 
 pdflang={English}}
\begin{document}

\maketitle
\begin{center}
\includegraphics[width=.9\linewidth]{test.pdf}
\end{center}
\end{document}

1 Answer 1

1

If you include this answer based on "#+ATTR_LATEX" between your #+END_SRC and #+RESULTS block, you should be able to resize the image through LaTeX export. Your code would look like this.

#+BEGIN_SRC asymptote :file test.pdf
<<Your Asymptote code here.>>
#+END_SRC

#+ATTR_LATEX: :width 0.2\textwidth
#+RESULTS:
<<The image Asymptote generated here.>>

Note that the "0.2" factor happened to work well with the document I was just working on; you might have to adjust it for your own use.

1
  • It is (always) a good idea to name your SRC blocks: that way, the RESULTS block is named as well and so when you evaluatte the SRC block again, no new RESULTS block is generated and you don't have to muck around with moving the ATTR_LATEX line and getting rid of the old RESULTS block.
    – NickD
    Commented Jul 22, 2021 at 4:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.