MATLAB: How to remove the Paragraph environment generated when publishing an MATLAB file into LaTeX in MATLAB 7.8 (R2009a)

\begin{par}\end{par}latexMATLABparagraphpublishremove

When I publish the following comments in an MATLAB file into LaTeX format:
% This is an example? on displaying comments with LATEX.
% This is the second line.
%
% $$ \sin(\pi x) = 0 $$
MATLAB generates the following LaTeX file:
\begin{par} This is an example? on displaying comments with LATEX. This is the second line. \end{par} \vspace{1em}
\begin{par} $$ \sin(\pi x) = 0 $$ \end{par} \vspace{1em}
I want to remove the Paragraph environment.

Best Answer

MATLAB uses an XSL stylesheet to do the conversion. To remove the Paragraph environment, modify the XSL stylesheet accordingly. For example, see steps below:
1) Execute the following MATLAB commands:
% The directory containing the stylesheet
ssdir = fullfile(matlabroot, 'toolbox', 'matlab', 'codetools', 'private');
% Make a backup of the old stylesheet
copyfile(fullfile(ssdir,'mxdom2latex.xsl'),fullfile(ssdir,'mxdom2latex.xsl.old'))
2) Open 'mxdom2latex.xsl' from 'ssdir' directory in MATLAB:
edit([ssdir filesep 'mxdom2latex.xsl'])
3) Near line 104 in ‘mxdom2latex.xsl’, you will see the following:
<!-- HTML Tags in text sections -->
<xsl:template match="p">\begin{par}
<xsl:apply-templates/><xsl:text>
\end{par} \vspace{1em}
</xsl:text>
</xsl:template>
Remove \begin{par}, \end{par}, and \vspace{1em}:
<xsl:template match="p">
<xsl:apply-templates/><xsl:text>
</xsl:text>
</xsl:template>
4) Save the changes
5) Publish to LaTeX