PreTeXtBook / pretext

PreTeXt: an authoring and publishing system for scholarly documents
https://pretextbook.org
Other
266 stars 208 forks source link

Custom parameters for Asymptote (feature request) #1363

Closed sean-fitzpatrick closed 3 years ago

sean-fitzpatrick commented 4 years ago

Currently we have a <latex-image-preamble> but no <asymptote-preamble>. Would it be possible to create something like this? The extract-asymptote.xsl template writes the contents of the <macros> section to each .asy file, which ensures that any LaTeX macros used in an Asymptote label get read correctly.

But it would be useful to be able to author Asymptote diagrams using globally defined parameters for settings like pen colour. These could be imported in a style file. Possible solution: in

<xsl:template match="image/asymptote">
    <xsl:variable name="filebase">
        <xsl:apply-templates select=".." mode="visible-id" />
    </xsl:variable>
    <!-- Do not use directories here, as Windows paths will get mangled -->
    <!-- Instead, set working directory before applying stylesheet      -->
    <exsl:document href="{$filebase}.asy" method="text">
        <xsl:text>usepackage("amsmath");&#xa;</xsl:text>
        <xsl:text>texpreamble("&#xa;</xsl:text>
        <xsl:value-of select="$latex-macros" />
        <xsl:text>");&#xa;&#xa;</xsl:text>
        <xsl:value-of select="."/>
    </exsl:document>
 </xsl:template>

we add a line (or lines) after <xsl:text>");&#xa;&#xa;</xsl:text> that writes import (style file name).asy. That style file could be specified using a string parameter or in the publisher file.

Maybe that is easier than adding a new element (asymptote-preamble) to the schema.

sean-fitzpatrick commented 4 years ago

Note that (I'm pretty sure) we can't just write what we need into the <macros> section, since we need to use Asymptote syntax and not LaTeX. But maybe @mdoob knows how to do this?

rbeezer commented 4 years ago

I had this idea, but had not caught up with list traffic enough to think carefully before proposing it. Your Asymptote source is part of your overall source. So asymptote-preamble makes good sense to me.

Let's not get too fancy - whatever is in the element, it gets dropped into the asy code at the right place. So no extra style file to be managed? Or, said differently, the preamble element is the style file.

sean-fitzpatrick commented 4 years ago

Ok. I'll give that a try. Should be able to modify extract-asymptote.xsl for this. I think just dropping in something like <xsl:value-of select="$asymptote-preamble"> should work?

That variable needs to be defined somewhere, I think? I'll look at existing examples for clues

rbeezer commented 4 years ago

<xsl:value-of select="$docinfo/asymptote-preamble"/> which assumes the content is one giant text node.

There is a utility template to left-justify (strip excessive leading space, preserve indentation), but that may not be necessary here, unless folks want to the source code and want it pretty.

A PR would be great, as I won't have much time for this until the end of the month.

sean-fitzpatrick commented 4 years ago

Got it. I'll get on it tonight. Should be much easier than reconciling all 309 examples of Greg's Asymptote code.

mdoob commented 4 years ago

Bonjour a tous: hello from Quebec. I'm not quite in full contact.

Of course asymptote can read files and use conditionals based on the content. Nonetheless, it seems to me that adding a asymptote-preamble construction that parallels the one used for tikz makes more sense.

Cheers, Michael


Michael Doob Telephone: (204) 474-9796 Senior Scholar Department of Mathematics email: Michael.Doob@UManitoba.ca University of Manitoba Winnipeg, MB, Canada R3T 2N2


From: Rob Beezer notifications@github.com Sent: 02 September 2020 14:06 To: rbeezer/mathbook Cc: Michael Doob; Mention Subject: Re: [rbeezer/mathbook] Custom parameters for Asymptote (feature request) (#1363)

Caution: This message was sent from outside the University of Manitoba.

I had this idea, but had not caught up with list traffic enough to think carefully before proposing it. Your Asymptote source is part of your overall source. So asymptote-preamble makes good sense to me.

Let's not get too fancy - whatever is in the element, it gets dropped into the asy code at the right place. So no extra style file to be managed? Or, said differently, the preamble element is the style file.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/rbeezer/mathbook/issues/1363#issuecomment-685905713, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAVJL7XSMNG754WDL3EH3KDSD2CSZANCNFSM4QTMCWLQ.

sean-fitzpatrick commented 4 years ago

I am now chuckling at my "I'll get on it tonight" claim. Still trying to get a reasonable (colour) PDF out the door, and classes start tomorrow (so I should do something about my unfinished syllabus). But this is still on my list. I'll get on it once Greg finishes updating the asymptote code.

sean-fitzpatrick commented 3 years ago

I think this is resolved by #1385 and can be closed.