Captions under figures

Is there a way to modify the 6x9book.xslt so that cations are set under the figures instead of above?

The 6x9 stylesheet uses the memoir class, which you can find documentation for here. Download the linked PDF, and specifically you might find your answer in section II, chapter 11, which addresses captions and floats. I haven’t looked at it too closely though, so if that isn’t what you need, it might be some place else in there.

Thank you for the link! I could not find any help there; but it looks like Figure captions are normally placed below the figure (as I want). So may be there is something in the xslt definition that changes this? I cant find any reference to captions there, however.

This is the code for a figure produced by the latex converter, and places caption above the figure:

\begin{figure}
\caption{Bukkehorn}
\label{horn}
\begin{center}
\resizebox{!}{100pt}{\includegraphics{bukkehorn.pdf}}
\end{center}
\end{figure}

If I move the caption command below the \includegraphics-command, I get the caption below the figures. Can I change the xslt file so that I get it this way?

Yes, quite easily. I would just duplicate the xhtml2latex.xslt file, and check around line 730 of that. You should see this:

		<xsl:if test="@title">
			<xsl:text>\caption{</xsl:text>
			<xsl:apply-templates select="@title"/>
			<xsl:text>}
</xsl:text>
		</xsl:if>

That block, if moved below the figure generator section (but still inside the html:img template match container), should do the trick. For me that is around line 811.

Note: Editing this file will actually affect all of the LaTeX based XSLT files, not just 6x9book.xslt. I’m guessing that would be what you want to do anyway. Most of these work by inheriting from each other. The chain goes 6x9book.xslt << memoir.xslt << xhmlt2latex.xslt.

Yes, that’s what I want. I dont find an exact match in my xhtml2latex.xslt-file; the closest is

<xsl:template match=“html:img”>
xsl:text\begin{figure}
</xsl:text>
<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>
I tried to cut the part starting with <xsl:if test="@title"> and ending with </xsl:if>, but I dont know enough of the syntax here to find a right way to paste it in again. I tried further down at

xsl:text\resizebox{1\linewidth}{!}{</xsl:text>
</xsl:if>
xsl:text\includegraphics{</xsl:text>
<xsl:value-of select="@src"/>
xsl:text}}
\end{center}
\end{figure}

at various points without luck; getting error messages pointing to the lines here when exporting.
More hints? Thanks anyway so far!!

To produce a LaTeX captioned figure that looks like this:

\begin{figure}
\label{goodselection}
\begin{center}
\resizebox{1\linewidth}{!}{\includegraphics{ ... }}
\caption{A safe selection}
\end{center}
\end{figure}

Cut and paste this in place of the current image section in xhtml2latex.xslt

	<!-- images -->
	<xsl:template match="html:img">
		<xsl:text>\begin{figure}
</xsl:text>
		<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>}}
</xsl:text>
		<xsl:if test="@title">
			<xsl:text>\caption{</xsl:text>
			<xsl:apply-templates select="@title"/>
			<xsl:text>}
</xsl:text>
		</xsl:if>
		<xsl:text>\end{center}
\end{figure}
</xsl:text>
	</xsl:template>

Note this is the whole thing. If that doesn’t work for you, we might be using a slightly different version of MMD. In that case, note the syntax usage near the end. Make sure you are not inserting the xsl:if inside of an xsl:text block.

Thanks again for the help!
One problem, though. I now downloaded a new version of MultiMarkDown, MultiMarkdown Version 2.0.b3, where $Id: xhtml2latex.xslt 411 2007-05-28 14:23:42Z fletcher $
and found the line numbers close to what you have indicated; pasted the whole thing, and get the export to work. Output is produced - figures and .tex-file in a folder, but the .tex-file is empty.

I have tried this several times, and also got the same effect with the old version.

If I try to cut and paste according to the first insructions, I get
compilation error: file …/XSLT/xhtml2latex.xslt line 802 element text
xsltParseTemplateContent: xslt:text content problem
during export…

…finally solved it - put the if-block between the \end{center} and \end{figre}-lines, and terminated the text block ablove and started a new below…

Learned a bit in the process. Thanks for the help again!

No problem. Glad you got it working. Learning a little XSLT (enough to tweak output) can be a very rewarding experience for the advanced Scrivener user. :slight_smile: