1

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} ?

1 Answer 1

1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .