LaTeX forum ⇒ Generallistings | 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

Postby nifty » Mon Oct 10, 2011 3:36 pm

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

roll.html has this:
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8"/>
  5. <title>JavaScript Temperature Converter</title>
  6. </head>
  7. <body>
  8. <h1>Temperature Conversion</h1>
  9. <p>
  10. <input type="text" id="temperature" />
  11. <input type="button" id="f_to_c" value="F to C" />
  12. <input type="button" id="c_to_f" value="C to F" />
  13. </p>
  14. <p id="result"></p>
  15. <script src="temperature.js"></script>
  16. </body>
  17. </html>

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

My file looks like this:
myfile.png
myfile.png (146.58 KiB) Viewed 4405 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.

User avatar
localghost
Site Moderator
Posts: 9204
Joined: Fri Feb 02, 2007 12:06 pm

Postby localghost » Mon Oct 10, 2011 4:57 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.
  1. \documentclass[11pt]{article}
  2. \usepackage[T1]{fontenc}
  3. \usepackage{listings}
  4. \usepackage[dvipsnames]{xcolor}
  5.  
  6. \lstset{%
  7. basicstyle=\small\ttfamily,
  8. breaklines=true,
  9. columns=fullflexible,
  10. frame=single,
  11. frameround=tttt,
  12. showstringspaces=false
  13. }
  14.  
  15. \begin{document}
  16. \lstinputlisting[%
  17. language=HTML,
  18. backgroundcolor=\color{Apricot!25},
  19. identifierstyle=\color{magenta!50!black},
  20. stringstyle=\color{blue}
  21. ]{scr/html/roll.html}
  22. \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
reproduction.png
The output as obtained by the given code.
reproduction.png (67.72 KiB) Viewed 4405 times
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ 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

Postby johnkimber » Thu Apr 25, 2019 8:16 am

Check with this..color codes


Return to “General”

Who is online

Users browsing this forum: No registered users and 6 guests