1

I noticed that tex4ht do not generate correct code for typesetting Matlab code listing. It does not like .^ in the Matlab code, and it generates funny looking character in its place.

MWE

\documentclass[12pt]{article}%
\usepackage{amsmath,mathtools}
\usepackage[framed,autolinebreaks]{mcode}%
\begin{document}
\begin{lstlisting}
a.^2;
\end{lstlisting}
\end{document}

Compiled used

make4ht --lua -u foo.tex "htm"

This is the HTML generated

Mathematica graphics

<?xml version="1.0" encoding="utf-8" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->  
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head><title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<!-- xhtml,htm,charset=utf-8,html --> 
<meta name="src" content="foo.tex" /> 
<meta name="date" content="2016-01-29 00:44:00" /> 
<link rel="stylesheet" type="text/css" href="foo.css" /> 
</head><body> 
<!--l. 7-->
<div class="lstlisting" id="listing-1"><span class="label"><a 
 id="x1-2r1"></a></span><span 
class="pcrr8r-">a.</span><span 
class="pcrr8r-">Ȉ2;</span>   
</div> 
</body></html> 

I can't used \usepackage[T1]{fontenc} which would have fixed this, since when I used \usepackage[T1]{fontenc} before in other places with tex4ht, it caused many other problems, so I stopped using it. I do not now remember now what the problems were, but were related to some problem with how the HTML looked. When I stopped \usepackage[T1]{fontenc} then, it fixed the HTML. But now I find I need it with mcode.

question is: Is it possible to resolve the above, without using \usepackage[T1]{fontenc}? or must one use \usepackage[T1]{fontenc}?

I use --lua and -u options always with make4ht.

-l,--lua  Use lualatex for document compilation
-u,--utf8  For output documents in utf8 encoding

Using TL 2015.

file lists:

*File List*
 article.cls    2014/09/29 v1.4h Standard LaTeX document class
  size12.clo    2014/09/29 v1.4h Standard LaTeX file (size option)
  tex4ht.sty    
 fontenc.sty
   t1enc.def    2005/09/27 v1.99g Standard LaTeX file
   t1enc.def    2005/09/27 v1.99g Standard LaTeX file
 amsmath.sty    2013/01/14 v2.14 AMS math features
 amstext.sty    2000/06/29 v2.01
  amsgen.sty    1999/11/30 v2.0
  amsgen.sty    1999/11/30 v2.0
  amsbsy.sty    1999/11/29 v1.2d
  amsopn.sty    1999/12/14 v2.01 operator names
mathtools.sty    2015/11/12 v1.18 mathematical typesetting tools
  keyval.sty    2014/10/28 v1.15 key=value parser (DPC)
    calc.sty    2014/10/28 v4.3 Infix arithmetic (KKT,FJ)
 mhsetup.sty    2010/01/21 v1.2a programming setup (MH)
   mcode.sty    2014/03/06 2.5
  xcolor.sty    2007/01/21 v2.11 LaTeX color extensions (UK)
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
   color.cfg    2007/01/18 v1.5 color configuration of teTeX/TeXLive
   dvips.def    2014/10/14 v3.0j Driver-dependent file (DPC,SPQR)
   dvips.def    2014/10/14 v3.0j Driver-dependent file (DPC,SPQR)
listings.sty    2015/06/04 1.6 (Carsten Heinz)
 lstmisc.sty    2015/06/04 1.6 (Carsten Heinz)
 lstmisc.sty    2015/06/04 1.6 (Carsten Heinz)
listings.cfg    2015/06/04 1.6 listings configuration
listings.cfg    2015/06/04 1.6 listings configuration
textcomp.sty    2005/09/27 v1.99g Standard LaTeX package
  ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
  ts1enc.def    2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file
   t1pcr.fd    2001/06/04 font definitions for T1/pcr.
   t1pcr.fd    2001/06/04 font definitions for T1/pcr.
  ts1cmr.fd    2014/09/29 v2.5h Standard LaTeX font definitions
  ts1cmr.fd    2014/09/29 v2.5h Standard LaTeX font definitions
graphicx.sty    2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR)
graphics.sty    2014/10/28 v1.0p Standard LaTeX Graphics (DPC,SPQR)
    trig.sty    1999/03/16 v1.09 sin cos tan (DPC)
graphics.cfg    2010/04/23 v1.9 graphics configuration of TeX Live
graphics.cfg    2010/04/23 v1.9 graphics configuration of TeX Live
3

The fontenc package shouldn't cause problems with tex4ht, although it is best to use it together with inputenc (or luainputenc in the case of LuaLaTeX). It would be nice if you could find any example where it fails and report it.

This code compiles fine:

\documentclass[12pt]{article}%
\usepackage[T1]{fontenc}
\usepackage[utf8]{luainputenc}
\usepackage{amsmath,mathtools}
\usepackage[framed,autolinebreaks]{mcode}%
\begin{document}
\begin{lstlisting}
a.^2;
\end{lstlisting}

\end{document}

I had to download mcode package, because it isn't included in TeX Live. It seems that it is just configuration for listings package. What is strange is that if I use only original listings with Matlab language, the file is compiles correctly even without fontenc. You can also use other project which provides Matlab configuration for listings, matlab-prettifier:

\documentclass[12pt]{article}%
\usepackage{amsmath,mathtools}
\usepackage{matlab-prettifier}
\begin{document}
\begin{lstlisting}[language=Matlab,style=Matlab-editor]
a.^2;
\end{lstlisting}
\end{document}

the result:

enter image description here

  • You have asked "It would be nice if you could find any example where it fails and report it.". I have just found an example. I used your code above, after This code compiles fine: exactly as is, but changed the matlab code line. I found big problem with the generated code in HTML. Do you want me to post this as separate question in this case or send it to tex4ht mailing list? The problem shows up when using --lua option again with make4ht. Using same code you have above. Thanks. – Nasser Feb 26 '16 at 16:28
  • @Nasser new question is fine, I think – michal.h21 Feb 26 '16 at 17:01

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.