@@ -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"/>
@@ -1384,14 +1385,32 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
13841385 </xsl:if>
13851386</xsl:template>
13861387
1388+ <!-- image sizing support -->
1389+ <xsl:template name="image-sizing">
1390+ <xsl:if test="$document-root//image">
1391+ <xsl:text>%% Define maxwidth variable for includegraphics
</xsl:text>
1392+ <xsl:text>%% recipe from https://texfaq.org/FAQ-grmaxwidth 
</xsl:text>
1393+ <xsl:text>\makeatletter
</xsl:text>
1394+
1395+ <xsl:text>\def\maxwidth{%
</xsl:text>
1396+ <xsl:text> \ifdim\Gin@nat@width>\linewidth
</xsl:text>
1397+ <xsl:text> \linewidth
</xsl:text>
1398+ <xsl:text> \else
</xsl:text>
1399+ <xsl:text> \Gin@nat@width
</xsl:text>
1400+ <xsl:text> \fi
</xsl:text>
1401+ <xsl:text>}
</xsl:text>
1402+ <xsl:text>\makeatother
</xsl:text>
1403+ </xsl:if>
1404+ </xsl:template>
1405+
13871406<!-- tcolorbox for images -->
13881407<xsl:template name="image-tcolorbox">
13891408 <xsl:if test="$document-root//image">
13901409 <xsl:text>%% "tcolorbox" environment for a single image, occupying entire \linewidth
</xsl:text>
13911410 <xsl:text>%% arguments are left-margin, width, right-margin, as multiples of
</xsl:text>
13921411 <xsl:text>%% \linewidth, and are guaranteed to be positive and sum to 1.0
</xsl:text>
13931412 <xsl:text>\tcbset{ imagestyle/.style={bwminimalstyle} }
</xsl:text>
1394- <xsl:text>\NewTColorBox{tcbimage}{mmm}{imagestyle,left skip=#1\linewidth,width=#2\linewidth}
</xsl:text>
1413+ <xsl:text>\NewTColorBox{tcbimage}{mmm}{imagestyle,left skip=#1\linewidth,width=#2\linewidth,halign=center }
</xsl:text>
13951414 <xsl:text>%% Wrapper environment for tcbimage environment with a fourth argument
</xsl:text>
13961415 <xsl:text>%% Fourth argument, if nonempty, is a vertical space adjustment
</xsl:text>
13971416 <xsl:text>%% and implies image will be preceded by \leavevmode\nopagebreak
</xsl:text>
@@ -9294,7 +9313,15 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
92949313 </xsl:with-param>
92959314 </xsl:call-template>
92969315 </xsl:variable>
9297- <xsl:text>\includegraphics[width=\linewidth</xsl:text>
9316+ <xsl:text>\includegraphics[width=</xsl:text>
9317+ <xsl:choose>
9318+ <xsl:when test="@width">
9319+ <xsl:text>\linewidth</xsl:text>
9320+ </xsl:when>
9321+ <xsl:otherwise>
9322+ <xsl:text>\maxwidth</xsl:text>
9323+ </xsl:otherwise>
9324+ </xsl:choose>
92989325 <xsl:if test="@rotate">
92999326 <xsl:text>,angle=</xsl:text>
93009327 <xsl:value-of select="@rotate"/>
0 commit comments