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.

How to accept three language different?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[brazil]{babel}
\usepackage{xcolor,tikz}
\usepackage{showexpl} % exibe codigos de figuras

% Definindo novas cores
\definecolor{amarelo}{rgb}{1,1,0.8}
\definecolor{verde}{rgb}{0,0.5,0}
\definecolor{cinza}{rgb}{.9,.9,.9}

% Configurando layout para mostrar codigos LaTeX
\usepackage{listings}
% explpreset eh usado no showexpl
% configurando para codigos das figuras
\lstset{explpreset={
     language=[LaTeX]TeX,
     basicstyle=\ttfamily\small, 
     identifierstyle=\color{black}, 
     keywordstyle=\color{blue}, 
     stringstyle=\color{verde}, 
     commentstyle=\color{red}, 
     extendedchars=true, 
     showspaces=false, 
     showstringspaces=false, 
     numbers=none,
     %numberstyle=\tiny,
     breaklines=true, 
     backgroundcolor=\color{amarelo}, 
     breakautoindent=true, 
     captionpos=b,
     xleftmargin=0pt,
     frame=none,   %%frame=single
     rframe={}
  }, % configurando para codigos LaTeX
     language=[LaTeX]TeX,
     basicstyle=\ttfamily\small, 
     identifierstyle=\color{black}, 
     keywordstyle=\color{blue}, 
     stringstyle=\color{verde}, 
     commentstyle=\color{red}, 
     extendedchars=true, 
     showspaces=false, 
     showstringspaces=false, 
     numbers=left,
     numberstyle=\tiny, 
     breaklines=true, 
     backgroundcolor=\color{cinza}, 
     breakautoindent=true, 
     captionpos=b,
     xleftmargin=0pt,
}

\definecolor{javared}{rgb}{0.6,0,0} % for strings
\definecolor{javagreen}{rgb}{0.25,0.5,0.35} % comments
\definecolor{javapurple}{rgb}{0.5,0,0.35} % keywords
\definecolor{javadocblue}{rgb}{0.25,0.35,0.75} % javadoc

\lstset{language=Java,
basicstyle=\ttfamily,
keywordstyle=\color{javapurple}\bfseries,
stringstyle=\color{javared},
commentstyle=\color{javagreen},
morecomment=[s][\color{javadocblue}]{/**}{*/},
numbers=left,
numberstyle=\tiny\color{black},
numbersep=10pt,
tabsize=4,
showspaces=false,
showstringspaces=false}

\begin{document}

\begin{lstlisting}
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[brazil]{babel}
\usepackage{lipsum}
% Definindo novas cores
\definecolor{amarelo}{rgb}{1,1,0.8}
\definecolor{verde}{rgb}{0,0.5,0}
\definecolor{cinza}{rgb}{.9,.9,.9}
\begin{document}
 \lipsum
\end{document}
\end{lstlisting}

\begin{lstlisting}
public class HelloWorldApp {
     public static void main (String argv[])
     {
          // Display string
          System.out.println("Hello World!");
     }
}
\end{lstlisting}

% requer o pacote showexpl
\begin{LTXexample}[width=4cm]
\begin{tikzpicture}
  \draw circle (1);
\end{tikzpicture}
\end{LTXexample}

\end{document}

I need LaTeX, Java and LTXexample. But LaTeX is gray, and Java is blue, and LTXexample is yellow.

share|improve this question

1 Answer 1

up vote 12 down vote accepted

Use the alsolanguage and/or \lstdefinestyle and/or \lstnewenvironment.

enter image description here

\documentclass[]{article}

\usepackage{accsupp}
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}

\usepackage{xcolor}

\usepackage{showexpl}


\lstdefinestyle{LaTeX}
{
    language={[LaTeX]TeX},
    alsolanguage={PSTricks},
    numbers=left,
    numbersep=1em,
    numberstyle=\tiny\color{red}\noaccsupp,
    frame=single,
    framesep=\fboxsep,
    framerule=\fboxrule,
    rulecolor=\color{red},
    xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,
    xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,
    breaklines=true,
    basicstyle=\small\tt,
    keywordstyle=\color{blue},
    commentstyle=\color[rgb]{0.13,0.54,0.13},
    backgroundcolor=\color{yellow!10},
    tabsize=2,
    columns=flexible,
    explpreset={},
    morekeywords={
        graphicspath,
        includegraphics,
        blinddocument,
    },
}

\lstdefinestyle{Java}
{
    language={Java},
    alsolanguage={[Sharp]C},
    numbers=left,
    numbersep=1em,
    numberstyle=\tiny\color{red}\noaccsupp,
    frame=single,
    framesep=\fboxsep,
    framerule=\fboxrule,
    rulecolor=\color{red},
    xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,
    xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,
    breaklines=true,
    basicstyle=\small\tt,
    keywordstyle=\color{blue},
    commentstyle=\color[rgb]{0.13,0.54,0.13},
    backgroundcolor=\color{cyan!10},
    tabsize=2,
    columns=flexible,
    morekeywords={
        Console,
        WriteLine,
        int,
    },
}


\lstnewenvironment{java}
{\lstset{style=Java}}
{}

\begin{document}


\begin{LTXexample}[style=LaTeX,pos=r]
    \LaTeXe\ is not for children!
\end{LTXexample}

\begin{lstlisting}[style=Java]
    public void Main()
    {
        Console.WriteLine("Java is not for children!");
    }
\end{lstlisting}

\begin{java}
    public void Main(string[] args)
    {
        Console.WriteLine("Java is not for children!");
    }
\end{java}


\end{document}
share|improve this answer

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.