Skip to content

Commit

Permalink
Listing filename basics
Browse files Browse the repository at this point in the history
  • Loading branch information
ascholerChemeketa committed Oct 22, 2024
1 parent ecc1196 commit e076032
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion examples/sample-article/sample-article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10015,7 +10015,9 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.

<p>A <c>program</c> may also be nested inside a <c>listing</c>, which behaves similar to a <c>figure</c>. You can provide a <c>caption</c>, and the listing will be numbered along with tables and figures. This then makes it possible to cross-reference the listing, such as <xref ref="listing-c-hello" text="type-global" />. It also removes the requirement of wrapping the <c>program</c> in a <c>sidebyside</c>. For technical reasons, the three examples above will not split across a page break in PDF output, but the placement inside a <c>listing</c> will allow splits, as you should see in at least one example following.</p>

<listing xml:id="listing-c-hello">
<p>If a <attr>filename</attr> is supplied for the listing, it will be rendered as part of the listing caption. Filenames do not have to be unique - thus a particular filename can "evolve" throughout a work.</p>

<listing xml:id="listing-c-hello" filename="helloworld.c">
<caption>C Version of <q>Hello, World!</q></caption>
<program language="c">
<input>
Expand Down
1 change: 1 addition & 0 deletions schema/pretext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,7 @@
element listing {
MetaDataCaption,
Landscape?,
attribute filename {"yes" | "no"}?,
(
Program |
Console
Expand Down
7 changes: 7 additions & 0 deletions xsl/pretext-html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,13 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
</span>
</xsl:otherwise>
</xsl:choose>
<!-- listings may have an @filename that should be displayed-->
<xsl:if test="self::listing[@filename]">
<xsl:call-template name="space-styled"/>
<span class="filename">
<xsl:value-of select="@filename"/>
</span>
</xsl:if>
<!-- When a listing has an activecode, the caption will be picked -->
<!-- up by the activecode, so we don't want to duplicate it. -->
<xsl:variable name="has-valid-activecode">
Expand Down
5 changes: 5 additions & 0 deletions xsl/pretext-latex.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -8610,6 +8610,11 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
<xsl:text>}{</xsl:text>
<xsl:apply-templates select="." mode="type-name"/>
<xsl:text>}{</xsl:text>
<xsl:if test="self::listing[@filename]">
<xsl:value-of select="@filename"/>
<xsl:text>\space</xsl:text>
</xsl:if>
<xsl:apply-templates select="." mode="caption-full"/>
<xsl:apply-templates select="." mode="caption-full"/>
<xsl:text>}{</xsl:text>
<xsl:apply-templates select="." mode="unique-id"/>
Expand Down

0 comments on commit e076032

Please sign in to comment.