Generallistings | Color in HTML Code

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

listings | Color in HTML Code

Post by nifty »

I have a document from the author and he is using the listings package. He has this code:

Code: Select all

\lstinputlisting[language=HTML]{scr/html/roll.html}
roll.html has this:

Code: Select all

<!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
author.png (149.26 KiB) Viewed 8571 times
My file looks like this:
myfile.png
myfile.png (146.58 KiB) Viewed 8571 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.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

listings | Color in HTML Code

Post by localghost »

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.

Code: Select all

\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.
The output as obtained by the given code.
reproduction.png (67.72 KiB) Viewed 8571 times
johnkimber
Posts: 1
Joined: Thu Apr 25, 2019 8:15 am

listings | Color in HTML Code

Post by johnkimber »

Check with this..color codes
Post Reply