3

I googled around, and did not see something about this. I just found out that one gets an error using mdframed with tex4ht.

\documentclass{article}%
\usepackage{mdframed}
\begin{document}
\begin{mdframed}
text
\end{mdframed}
\end{document}

htlatex foo.tex

gives

(/usr/local/texlive/2013/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2013/texmf-dist/tex/latex/latexconfig/graphics.cfg))

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.6 \end{mdframed}

? 

The above compiles with no problem using pdflatex and with latex. So it is clearly an issue with tex4ht. Strange that it compiles ok with latex foo.tex, yet the error above says Latex Error:

Is this a known issue? Anyone knows of a workaround? I would have to try to find alternative to mdframed since I need to compile document using pdflatex and htlatex. I just needed to put a frame around large text blocks that can contain more than one paragraph. I am sure I will find other ways to do this that will also work with tex4ht.

Using texlive 2013, on Linux

Update

Text4ht also failed with packaged framed !

\documentclass{article}%
\usepackage{framed}
\begin{document}
\begin{framed}
text

test
\end{framed}    
\end{document}

htlatex foo.tex

gives

(/usr/local/texlive/2013/texmf-dist/tex/generic/tex4ht/html4-math.4ht))
(./foo.aux)
! You can't use `\prevdepth' in horizontal mode.
\nointerlineskip ->\prevdepth 
                              -\@m \p@ 
l.8 \end{framed}

? 

May be putting frame around text with tex4ht can not be done. Will keep trying....

  • I don't get an error typesetting your first example, at least. (latex foo.tex; tex4ht foo.tex.) That said, I don't get text in a framed box either. (But I do get a usable html file.) – cfr Jun 9 '14 at 1:52
  • oh, the command is htlatex foo.tex that is the one I use. Sorry I wrote tex4ht there, since the tag was tex4ht. I'll correct. – Nasser Jun 9 '14 at 1:59
  • Is \fbox{\parbox{.8\textwidth}{text}} an option? Probably one of the packages for making fancier boxes based on \fbox should be fine, too. That allows paragraphs (but not page breaks if that's even relevant in this case) and seems to work. – cfr Jun 9 '14 at 2:11
  • @cfr but fbox solution does not work. I tried that before. If you look at the HTML generated, you will see it removed the paragraph formatting. Screen shot !Mathematica graphics the above was from this file : !Mathematica graphics so it does not really work. pdflatex produces the correct output. – Nasser Jun 9 '14 at 2:17
  • I guess that's because it puts it into a table. – cfr Jun 9 '14 at 2:24
1

The support for framed and mdframed packages has been recently added to tex4ht, the changes will be distributed with TeXLive 2017. You can test the configuration for mdframed with the following configuration file, mdframed.4ht:

\NewConfigure{mdframed}{2}
\NewConfigure{mdframedstyle}{1}
\newcount\mdf:env:cnt
\def\mdf:id{mdframed-\the\mdf:env:cnt}
\def\mdf@trivlist#1{\global\advance\mdf:env:cnt by1\relax\a:mdframed\a:mdframedstyle}
\def\endmdf@trivlist{\b:mdframed}
 \def\mdf@lrbox#1{}
 \def\endmdf@lrbox{}

\@ifpackageloaded{xcolor}{%
\def\get:xcolorcss#1#2{%
   \expandafter\extractcolorspec\expandafter{#1}{\tsf:color}%
   \expandafter\convertcolorspec\tsf:color{HTML}\tsf:color%
   \edef#2{\#\tsf:color}%
}}{}
    \Configure{mdframed}{%
  \ifvmode\IgnorePar\fi\EndP\HCode{<div class="mdframed" id="\mdf:id">}\par
}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}\par}

% use fallback macro when xcolor package haven't been loaded
\ifdefined\get:xcolorcss\else\def\get:xcolorcss#1#2{\def#2{#1}}\fi

\Configure{mdframedstyle}{%
  \get:xcolorcss{\mdf@backgroundcolor}\mdf:bgcolor
  \get:xcolorcss{\mdf@linecolor}\mdf:bordercolor
  \get:xcolorcss{\mdf@fontcolor}\mdf:fontcolor
  \def\mdf:border{\ifx\mdfl@linewidth\relax 1px\else\mdfl@linewidth\fi\space solid \mdf:bordercolor}
  \Css{\#\mdf:id{border:\mdf:border; background-color: \mdf:bgcolor; color:\mdf:fontcolor;}}
  \global\let\mdfl@linewidth\relax
}
\Hinput{mdframed}

This configuration redefines some internal mdframed macros which cause the issue and use them to insert the HTML code. There are two configurations, \Configure{mdframed} and \Configure{mdframedstyle}. The first one is used for HTML tag insertion, the second one for configuring the style. Every mdframed environment produces <div> element with unique id, so we can style them individually.

To illustrate that, here is an example:

\documentclass{article}
\usepackage{mdframed}
\usepackage{xcolor}
\begin{document}

some text
\begin{mdframed}[backgroundcolor=yellow!40,linecolor=blue,linewidth=4]
  Colorized frame
\end{mdframed}
some text between
\begin{mdframed}
  Plain frame
\end{mdframed}
another instance
\begin{mdframed}[backgroundcolor=yellow!40,linecolor=blue,linewidth=4]
  Colorized frame
\end{mdframed}
\end{document}

Which produces the following web page:

enter image description here

2

Use \fbox but include the text in a minipage. The following compiles Ok with tex4ht and produces the required frame around the text. The options for minipage can be adjusted as needed.

\documentclass{article}%    
\begin{document}

\fbox{
\begin{minipage}[t]{\textwidth}
line 1

line 2

line 3
\end{minipage}
}     
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.