I have many Asymptote files and they all need the LaTeX package siunitx. One way of doing this is to include the line usepackage("siunitx"); in every single file, but I would like to do this automatically for all asy files. I am trying to use a config.asy file in the same directory of those asy files. However, when I compiled with Asymptote (2.65), there is no error but there is also no png or other kind of output files produced.

My config.asy file:

import plain;


My mwe.asy file:

draw(Label("\SI{2}{\centi\meter}"), (0,0)--(2,2));

When compiled by asy mwe.asy, nothing is produced and also there is no error. What's wrong with my config.asy? or is there any other smarter way to automatically load some LaTeX packages for all the asy files?

EDIT My understanding is that config.asy is loaded by all asy files before doing anything else, that's why I am trying to use configuration file instead of something like import mytexpreamble.asy in every single asy file.

  • If I delete the line settings.command="usepackage('siunitx')"; in config.asy and add either usepackage("siunitx"); or texpreamble("\usepackage{siunitx}");, it will give me a correct png file after compiling; however if I put either usepackage("siunitx"); or texpreamble("\usepackage{siunitx}"); together with the line settings.command="usepackage('siunitx')"; in config.asy, it also produces nothing.
    – bingung
    May 7, 2020 at 22:39
  • Yes but then I would need to put usepackage("siunitx"); into every single asy file I have. I don't want to do this, I want to put a single line in the configuration file config.asy and every asy file will then load those settings. Leaving settings.command="usepackage('siunitx')"; out in config.asy will give me error if I don't include usepackage("siunitx"); in mwe.asy
    – bingung
    May 7, 2020 at 22:52
  • My understanding is that the config.asy is loaded by all asy files before doing anything else, that's why I am trying to use configuration file instead of something like import mytexpreamble.asy in every single asy file.
    – bingung
    May 7, 2020 at 23:01
  • @Schrödinger'scat no worry I will just clarify a bit in my question.
    – bingung
    May 7, 2020 at 23:11
  • config.asy is documented here. One possible explanation: perhaps the directory from which asy is being run is not the same as the directory containing all the asy files? One possible workaround: try putting config.asy in the (new) .asy directory under your home directory. May 8, 2020 at 17:45

2 Answers 2


I'm sure, there is a better and proper way to achieve this, but a quick-and-dirty fix is this:

copy plain.asy to the directory of those asy files and insert the line


at the end of it.

Actually, the code in the plain.asy suggests that if there is a command specified in settings.command, the Asymptote executes it and exits immediately after that.

You can instead use


but in this case the command


must be present in the beginning of the asy file.

  • Thanks! Didn't aware there is an exit(); at the end of command, so settings.user is the thing I should look for. While I see no harm in putting the usepackage("siunitx"); in plain.asy (at least in this case), it seems using usersetting(); with settings.user is a better practice. I guess it is designed for this purpose.
    – bingung
    May 8, 2020 at 23:48

It looks like there is a command texpreamble that might do what you need.

From https://sourceforge.net/p/asymptote/discussion/409349/thread/abc87704/ :

In the file config.asy you can set


and, in the file common.asy, you must put:



  • Thanks! This approach has the benefit of including also the user-defined functions into a single common.asy file, but will need to create an extra file common.asy. Whether settings.user with usersetting(); or autoimport is better seems depend on the user case.
    – bingung
    May 9, 2020 at 11:14

You must log in to answer this question.

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