Two-column images HOW-TO

Hi all,

Currently in the process of writing a conference paper and came across the need to place an image in a two-column layout that would span both columns. The answer is to use figure* instead of figure (eg \begin{figure*}), but I wanted to add support to it at write-time. So, here’s a how-to (suggestions are welcome!).

This goes in your XHTML2Latex file, instead of the current section under

<!-- images --> <xsl:template match="html:img"> <xsl:choose> <xsl:when test="@twocolumn"> <xsl:text>\begin{figure*}[t!] </xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>\begin{figure} </xsl:text> </xsl:otherwise> </xsl:choose> <xsl:if test="@title"> <xsl:text>\caption{</xsl:text> <xsl:apply-templates select="@title"/> <xsl:text>} </xsl:text> </xsl:if> <xsl:if test="@id"> <xsl:text>\label{</xsl:text> <xsl:value-of select="@id"/> <xsl:text>} </xsl:text> </xsl:if> <xsl:text>\begin{center} </xsl:text> <xsl:if test="@width|@height"> <!-- there are dimensions, so use them --> <!-- Basically, we allow any units covered by LaTeX, even if they are not allowed in XHTML. px is converted to pt. If no units, then assume pt. --> <xsl:text>\resizebox{</xsl:text> <xsl:choose> <xsl:when test="@width"> <xsl:call-template name="replace-substring"> <xsl:with-param name="original"> <xsl:value-of select="@width"/> </xsl:with-param> <xsl:with-param name="substring"> <xsl:text>px</xsl:text> </xsl:with-param> <xsl:with-param name="replacement"> <xsl:text>pt</xsl:text> </xsl:with-param> </xsl:call-template> <xsl:if test="translate(@width, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.' ,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') = '' "> <!-- no units specified --> <xsl:text>pt</xsl:text> </xsl:if> </xsl:when> <xsl:otherwise> <xsl:text>!</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:text>}{</xsl:text> <xsl:choose> <xsl:when test="@height"> <xsl:call-template name="replace-substring"> <xsl:with-param name="original"> <xsl:value-of select="@height"/> </xsl:with-param> <xsl:with-param name="substring"> <xsl:text>px</xsl:text> </xsl:with-param> <xsl:with-param name="replacement"> <xsl:text>pt</xsl:text> </xsl:with-param> </xsl:call-template> <xsl:if test="translate(@height, 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.' ,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') = '' "> <!-- no units specified --> <xsl:text>pt</xsl:text> </xsl:if> </xsl:when> <xsl:otherwise> <xsl:text>!</xsl:text> </xsl:otherwise> </xsl:choose> <xsl:text>}{</xsl:text> </xsl:if> <xsl:if test="not(@width|@height)"> <!-- if no dimensions, then ensure it fits on page (of course, this also goes to "max zoom"...) --> <xsl:text>\resizebox{1\linewidth}{!}{</xsl:text> </xsl:if> <xsl:text>\includegraphics{</xsl:text> <xsl:value-of select="@src"/> <xsl:text>}} \end{center} </xsl:text> <xsl:choose> <xsl:when test="@twocolumn"> <xsl:text>\end{figure*} </xsl:text> </xsl:when> <xsl:otherwise> <xsl:text>\end{figure} </xsl:text> </xsl:otherwise> </xsl:choose> </xsl:template>

Now, in your MMD files (in Scrivener) you can write something like:


[myimagename]: myimage.png “My Image” width=400, twocolumn=true

And your image will now float and become a two-column image. Hope that helps someone else!