Inconsistent color names in Asymptote vs elsewhere

14 views
Skip to first unread message

Gabriel Indurskis

unread,
May 25, 2025, 12:10:08 AM5/25/25
to PreTeXt support
Hi everybody,

I've run into the problem of color names being inconsistent between Asymptote and elsewhere (in math mode). For example, in Asymptote, the color "darkgreen" is predefined, but not in regular LaTeX.   I know using color too much is not recommended, but there are a few instances where I would like to highlight certain things in a math environment to match an accompanying figure.

I've tried to solve this by using a \definecolor command (provided by the xcolors LaTeX package, which I assumed to be used by default), but didn't know where to put this. I've tried in the <macros> section of docinfo.ptx, but that causes errors when (re)generating Asymptote figures (with no clear error message - it took me forever to figure out the cause). (By the way, this fails even if I use a name which shouldn't exist in Asymptote, like "mydarkgreen".)

So my (possibly quite ignorant) questions:

1) Is there a way to define colors centrally, and if so, where?
2) Are there debug options for pretext-cli to better explain why Asymptote compilations failed?

Thanks in advance!

Sean Fitzpatrick

unread,
May 25, 2025, 12:25:59 AM5/25/25
to pretext...@googlegroups.com

You can run the CLI with 'pretext -v debug ' at the front.
This preserves temporary directories, and the debug messages will give you the location.

The temp directory will contain the .asy files used at build time.

What I like to do is copy the contents of one of the files, and then paste it in the Asymptote renderer at
http://asymptote.ualberta.ca/

For this error, you'll discover that part of the problem is that Asymptote itself doesn't give a very useful error message on this one.

I don't think there's much to be done about Asymptote using different colour options than LaTeX.
As far as the incompatibility with xcolor, you could ask on the Asymptote forum (I think you can get to it via asymptote.sourceforge.io), or look into whether it would be possible to modify the Asymptote extraction template to ignore that package.
(It copies over the content of macros because you might reasonably expect any LaTeX macros you've defined to work in your Asymptote labels.


--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pretext-support/6f1936ad-bd8f-45da-8742-511fa402737en%40googlegroups.com.

Rob Beezer

unread,
May 25, 2025, 1:43:57 PM5/25/25
to pretext...@googlegroups.com
We have different preambles and macros available for use in #docinfo. And they
can be controlled by the use of versions. In other words, you can use different
variants of preambles for different situations. Maybe a different version could
be used to build Asymptote images? Yes, that'd be a mess with the CLI, but you
could use the pretext/pretext script to build those images and *save* them
into your repository (sorry, Brad!). You'd still want to keep the CLI from
clobbering them.

Or, could macros fron one or the other (Asymptote vs LaTeX) define some common
set of color names?

Is our automatic loading of xcolor for all LaTeX output part of the problem?
Options like dvipsnames and svgnames?

Its clear I don't have my head wrapped around this one entirely, but maybe some
ideas here might help.

Rob

On 5/24/25 21:25, Sean Fitzpatrick wrote:
> You can run the CLI with 'pretext -v debug ' at the front.
> This preserves temporary directories, and the debug messages will give you the
> location.
>
> The temp directory will contain the .asy files used at build time.
>
> What I like to do is copy the contents of one of the files, and then paste it in
> the Asymptote renderer at
> http://asymptote.ualberta.ca/ <http://asymptote.ualberta.ca/>
>
> For this error, you'll discover that part of the problem is that Asymptote
> itself doesn't give a very useful error message on this one.
>
> I don't think there's much to be done about Asymptote using different colour
> options than LaTeX.
> As far as the incompatibility with xcolor, you could ask on the Asymptote forum
> (I think you can get to it via asymptote.sourceforge.io <http://
> asymptote.sourceforge.io>), or look into whether it would be possible to modify
> email to pretext-suppo...@googlegroups.com <mailto:pretext-
> support+u...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/pretext-
> support/6f1936ad-bd8f-45da-8742-511fa402737en%40googlegroups.com <https://
> groups.google.com/d/msgid/pretext-support/6f1936ad-
> bd8f-45da-8742-511fa402737en%40googlegroups.com?
> utm_medium=email&utm_source=footer>.
>
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pretext-suppo...@googlegroups.com <mailto:pretext-
> support+u...@googlegroups.com>.
> CAH%2BNcPYfUdmAjzEhE9mtT%2BS2TyhU2-_-a0Ctc5-R%2B6WYnzP-Zg%40mail.gmail.com
> <https://groups.google.com/d/msgid/pretext-support/
> CAH%2BNcPYfUdmAjzEhE9mtT%2BS2TyhU2-_-a0Ctc5-R%2B6WYnzP-Zg%40mail.gmail.com?
> utm_medium=email&utm_source=footer>.

Gabriel Indurskis

unread,
May 25, 2025, 4:48:51 PM5/25/25
to pretext...@googlegroups.com
Thanks Sean and Rob for the detailed answers, it's much appreciated.

After some more testing, I've found an easy (and in retrospect possibly obvious) solution, which might be worthwhile adding to the documentation somewhere:

- only use standard color names defined by xcolors, some of which use CamelCase names, see for example https://www.overleaf.com/learn/latex/Using_colors_in_LaTeX for a list.
- in Asymptote figures, the same color names (apart from a few basic ones) can only be used after issuing the `import texcolors;` command. (The default color palette in asymptote uses lower-case names, some of which match the basic TeX colors, but some of which - like `darkgreen` are not defined by xcolors, or are actually slightly different colors.  See https://asymptote.sourceforge.io/doc/Pens.html)
- avoid defining custom colors with \definecolors{}, as that causes compilation errors with Asymptote.

If one plans to use consistent colors inside and outside of Asymptote often, one can make the `import texcolors;` command a default, by including it (with other desired default commands) in docinfo.ptx inside the <asymptote-preamble> tag, e.g.:

<asymptote-preamble>
import texcolors;
size(180,180);
usepackage("mathptmx");
defaultpen(TimesRoman());
</asymptote-preamble>

(Note that changes like these in docinfo.ptx might require a manual run of `pretext generate` to force regeneration of the asymptote figures.)

Cheers,

Gabriel

To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pretext-support/MTAwMDAxMS5iZWV6ZXI.1748195030%40pnsh.

Sean Fitzpatrick

unread,
May 26, 2025, 11:22:58 AM5/26/25
to PreTeXt support
If you can manage with the default colour options in LaTeX, Asymptote will let you use RGB syntax to specify colours, which should let you match Asymptote colours to the ones in LaTeX.
Reply all
Reply to author
Forward
0 new messages