Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've got a HTML document with JavaScript inside that I want to show in my article.

For that I would like to use my JavaScript and HTML formatting. How can I get the listings package to use two styles?

Is there something like language={HTML, JavaScript} ?

share|improve this question
add comment

1 Answer

There sure is, you can:

% Preamble
\usepackage[utf8]{inputenc}
\usepackage{listings}

   % Languages to use
\lstloadlanguages{C, sh}

   % My C preferences
\lstset{language=[ANSI]C,
        basicstyle=\sffamily, commentstyle=\slshape,
        extendedchars, frame=lines, numbers=none,
        float, floatplacement=ht, captionpos=b,
        xleftmargin=1em, xrightmargin=1em
       }

   % Handling of UTF-8 in listings is less than stellar, need an entry for   
   % each non-ASCII character
\lstset{literate={á}{{\'a}}1
                 {é}{{\'e}}1
                 {í}{{\'\i}}1
                 {ó}{{\'o}}1
                 {ú}{{\'u}}1
                 {ü}{{\"u}}1
                 {Á}{{\'A}}1
                 {ñ}{{\~n}}1
                 {É}{{\'E}}1
                 {Í}{{\'I}}1
                 {Ó}{{\'O}}1
                 {Ú}{{\'U}}1
                 {Ü}{{\"U}}1
                 {Ñ}{{\~N}}1
                 {¿}{{?`}}1
                 {¡}{{!`}}1
        }

% Document body
  % Code inline
... \lstinline[language=C]!a * x + b * y + c * (-(u + v))! ...
  % Code from an external file as float
\lstinputlisting[language=C,
                   xleftmargin=3em, numbers=left,
                   caption={Ordenamiento por inserción},
                   label=lst:insercion]
                   {code/insertion.c}

There are some supposed UTF-8 clean versions around, but they didn't work for me.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.