## LaTeX forum ⇒ General ⇒ listings | Color in HTML Code

LaTeX specific issues not fitting into one of the other forums of this category.
nifty
Posts: 16
Joined: Sat Oct 09, 2010 4:24 pm

### listings | Color in HTML Code

I have a document from the author and he is using the listings package. He has this code:
\lstinputlisting[language=HTML]{scr/html/roll.html}

roll.html has this:
<!doctype html><html>   <head>     <meta charset="UTF-8"/>     <title>JavaScript Temperature Converter</title>   </head>   <body>     <h1>Temperature Conversion</h1>     <p>       <input type="text" id="temperature" />       <input type="button" id="f_to_c" value="F to C" />       <input type="button" id="c_to_f" value="C to F" />     </p>     <p id="result"></p>     <script src="temperature.js"></script>   </body></html>

His PDF looks like this:
author.png (149.26 KiB) Viewed 3950 times

My file looks like this:
myfile.png (146.58 KiB) Viewed 3950 times

Notice the coloring of "charset," "id," and the words between <title> and </title>. Any ideas on why the difference in color? He is also using a lot of Java code and that coloring seems to be correct. It is just when he uses the language=html.
Last edited by localghost on Mon Oct 10, 2011 5:34 pm, edited 1 time in total.
Reason: Preferably no external links (see Board Rules). Attachments go onto the forum server where possible.

localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm
nifty wrote:I have a document from the author and he is using the listings package. […]

Can't the author just leave the concerned piece of code to you so that you can reproduce the appearance? Nevertheless, a minimal example that shows your recent efforts would be good to get closer to a solution.

Anyway, you have to set the colors for identifiers and strings explicitly. From what I can see on the pictures you attached, I tried to reproduce the desired output.
\documentclass[11pt]{article}\usepackage[T1]{fontenc}\usepackage{listings}\usepackage[dvipsnames]{xcolor} \lstset{%   basicstyle=\small\ttfamily,   breaklines=true,   columns=fullflexible,   frame=single,   frameround=tttt,   showstringspaces=false} \begin{document}   \lstinputlisting[%     language=HTML,     backgroundcolor=\color{Apricot!25},     identifierstyle=\color{magenta!50!black},     stringstyle=\color{blue}   ]{scr/html/roll.html}\end{document}

It goes without saying that this is only a basic example which needs some adjustments, especially regarding the colors. Since you didn't provide any code, I can't explain why the pieces of text you mentioned are colored in your example.

And next time please upload attachments to the forum sever. External links can get lost with time and make a problem incomprehensible later. If necessary, convert and scale images to match the 256kb limit for single attachments.

Thorsten
Attachments
The output as obtained by the given code.
reproduction.png (67.72 KiB) Viewed 3950 times
LaTeX Community Moderator

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1

johnkimber
Posts: 1
Joined: Thu Apr 25, 2019 8:15 am
Check with this..color codes