@@ -405,6 +405,7 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
405405 <xsl:call-template name="chapter-start-number"/>
406406 <xsl:call-template name="equation-numbering"/>
407407 <xsl:call-template name="image-tcolorbox"/>
408+ <xsl:call-template name="image-sizing"/>
408409 <xsl:call-template name="tables"/>
409410 <xsl:call-template name="footnote-numbering"/>
410411 <xsl:call-template name="font-awesome"/>
@@ -1380,14 +1381,32 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
13801381 </xsl:if>
13811382</xsl:template>
13821383
1384+ <!-- image sizing support -->
1385+ <xsl:template name="image-sizing">
1386+ <xsl:if test="$document-root//image">
1387+ <xsl:text>%% Define maxwidth variable for includegraphics
</xsl:text>
1388+ <xsl:text>%% recipe from https://texfaq.org/FAQ-grmaxwidth 
</xsl:text>
1389+ <xsl:text>\makeatletter
</xsl:text>
1390+
1391+ <xsl:text>\def\maxwidth{%
</xsl:text>
1392+ <xsl:text> \ifdim\Gin@nat@width>\linewidth
</xsl:text>
1393+ <xsl:text> \linewidth
</xsl:text>
1394+ <xsl:text> \else
</xsl:text>
1395+ <xsl:text> \Gin@nat@width
</xsl:text>
1396+ <xsl:text> \fi
</xsl:text>
1397+ <xsl:text>}
</xsl:text>
1398+ <xsl:text>\makeatother
</xsl:text>
1399+ </xsl:if>
1400+ </xsl:template>
1401+
13831402<!-- tcolorbox for images -->
13841403<xsl:template name="image-tcolorbox">
13851404 <xsl:if test="$document-root//image">
13861405 <xsl:text>%% "tcolorbox" environment for a single image, occupying entire \linewidth
</xsl:text>
13871406 <xsl:text>%% arguments are left-margin, width, right-margin, as multiples of
</xsl:text>
13881407 <xsl:text>%% \linewidth, and are guaranteed to be positive and sum to 1.0
</xsl:text>
13891408 <xsl:text>\tcbset{ imagestyle/.style={bwminimalstyle} }
</xsl:text>
1390- <xsl:text>\NewTColorBox{tcbimage}{mmm}{imagestyle,left skip=#1\linewidth,width=#2\linewidth}
</xsl:text>
1409+ <xsl:text>\NewTColorBox{tcbimage}{mmm}{imagestyle,left skip=#1\linewidth,width=#2\linewidth,halign=center }
</xsl:text>
13911410 <xsl:text>%% Wrapper environment for tcbimage environment with a fourth argument
</xsl:text>
13921411 <xsl:text>%% Fourth argument, if nonempty, is a vertical space adjustment
</xsl:text>
13931412 <xsl:text>%% and implies image will be preceded by \leavevmode\nopagebreak
</xsl:text>
@@ -9277,7 +9296,15 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
92779296 </xsl:with-param>
92789297 </xsl:call-template>
92799298 </xsl:variable>
9280- <xsl:text>\includegraphics[width=\linewidth</xsl:text>
9299+ <xsl:text>\includegraphics[width=</xsl:text>
9300+ <xsl:choose>
9301+ <xsl:when test="@width">
9302+ <xsl:text>\linewidth</xsl:text>
9303+ </xsl:when>
9304+ <xsl:otherwise>
9305+ <xsl:text>\maxwidth</xsl:text>
9306+ </xsl:otherwise>
9307+ </xsl:choose>
92819308 <xsl:if test="@rotate">
92829309 <xsl:text>,angle=</xsl:text>
92839310 <xsl:value-of select="@rotate"/>
0 commit comments