简体   繁体   中英

In default latex-mode emacs $ character break color

I need to include HTML code in LaTeX and I'm using the listings package for that. The problem is that if there is a $ character in my HTML code the color of the word after $ is broken in Emacs. To get the correct color I need to use another $ .

For example:

\begin{lstlisting}
    var mapElement = $("#map")[0];

    var mapOptions = {
        center: new google.maps.LatLng(43.720741,10.408413),
        zoom: 10
    };
\end{lstlisting}

After the $ character the text in the rest of the document isn't highlighted correctly. I'm not using AUCTeX but the default latex-mode of Emacs.

Any ideas?

I had the same problem and found a nice work around at http://www.latex-community.org/forum/viewtopic.php?f=31&t=25036

Use the following to output a $ each time you type 4> in the Latex code:

\lstset{
        literate={4>}{\$}1
}

then put your listing code in as normal

\begin{lstlisting}
  ruby -e "4>(curl -fsSL\ https://raw.github.com/Homebrew/homebrew/go/install)"
\end{lstlisting}

which will work around highlighting issues and AucTeX will still look nice and pretty! (:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM