0

I have read the documentation of listings : http://mirror.utexas.edu/ctan/macros/latex/contrib/listings/listings.pdf . I would like to make RAML 1.0 code blocks with listings but there is no syntax color.

Can someone provide me one ?

Thanks.

PS: the raml 1.0 spec : https://github.com/raml-org/raml-spec/blob/master/versions/raml-10/raml-10.md

6
  • Since RAML is based on YAML you can use Jubobs solution here: tex.stackexchange.com/a/152856/29873
    – DG'
    May 20, 2017 at 19:33
  • Thanks. I just hoped someone has better way since his answer is 3 years old
    – jy95
    May 20, 2017 at 19:35
  • I mean with an proper \lstdefinelanguage^^ I have already another programming language set
    – jy95
    May 20, 2017 at 19:50
  • no offense but I don't use macro yet : I have seen so many latex template have problems with them ^^
    – jy95
    May 20, 2017 at 19:53
  • The newcommand ^^
    – jy95
    May 20, 2017 at 19:57

2 Answers 2

1

Since RAML is based on YAML you can use Jubobs solution here: tex.stackexchange.com/a/152856/29873

\documentclass{article}

\usepackage[dvipsnames]{xcolor}
\usepackage{listings}

\newcommand\YAMLcolonstyle{\color{red}\mdseries}
\newcommand\YAMLkeystyle{\color{black}\bfseries}
\newcommand\YAMLvaluestyle{\color{blue}\mdseries}

\makeatletter

% here is a macro expanding to the name of the language
% (handy if you decide to change it further down the road)
\newcommand\language@yaml{yaml}

\expandafter\expandafter\expandafter\lstdefinelanguage
\expandafter{\language@yaml}
{
  keywords={true,false,null,y,n},
  keywordstyle=\color{darkgray}\bfseries,
  basicstyle=\YAMLkeystyle,                                 % assuming a key comes first
  sensitive=false,
  comment=[l]{\#},
  morecomment=[s]{/*}{*/},
  commentstyle=\color{purple}\ttfamily,
  stringstyle=\YAMLvaluestyle\ttfamily,
  moredelim=[l][\color{orange}]{\&},
  moredelim=[l][\color{magenta}]{*},
  moredelim=**[il][\YAMLcolonstyle{:}\YAMLvaluestyle]{:},   % switch to value style at :
  morestring=[b]',
  morestring=[b]",
  literate =    {---}{{\ProcessThreeDashes}}3
                {>}{{\textcolor{red}\textgreater}}1
                {|}{{\textcolor{red}\textbar}}1
                {\ -\ }{{\mdseries\ -\ }}3,
}

% switch to key style at EOL
\lst@AddToHook{EveryLine}{\ifx\lst@language\language@yaml\YAMLkeystyle\fi}
\makeatother

\newcommand\ProcessThreeDashes{\llap{\color{cyan}\mdseries-{-}-}}

\begin{document}

\begin{lstlisting}[language=yaml]
#%RAML 1.0
title: A CRUD API for Users and Groups

uses:
  example: annotations.1_0.yaml

/things:
  description: All the users
  get:
    responses:
      200:
        body:
          application/json:
            examples: !include examples.yaml
\end{lstlisting}
\end{document}

enter image description here

0
\usepackage{listings}
\usepackage{color}

% RAML langauge : listings language close to YAML
\newcommand\YAMLcolonstyle{\color{red}\mdseries}
\newcommand\YAMLkeystyle{\color{black}\bfseries}
\newcommand\YAMLvaluestyle{\color{blue}\mdseries}

\lstdefinelanguage{RAML}{
    keywords={true,false,null,y,n},
    keywordstyle=\color{darkgray}\bfseries,
    basicstyle=\YAMLkeystyle,                                 % assuming a key comes first
    sensitive=false,
    comment=[l]{\#},
    morecomment=[s]{/*}{*/},
    commentstyle=\color{purple}\ttfamily,
    stringstyle=\YAMLvaluestyle\ttfamily,
    moredelim=[l][\color{orange}]{\&},
    moredelim=[l][\color{magenta}]{*},
    moredelim=**[il][\YAMLcolonstyle{:}\YAMLvaluestyle]{:},   % switch to value style at :
    morestring=[b]',
    morestring=[b]",
    literate =    {---}{{\ProcessThreeDashes}}3
    {>}{{\textcolor{red}\textgreater}}1     
    {|}{{\textcolor{red}\textbar}}1 
    {\ -\ }{{\mdseries\ -\ }}3,
}

You must log in to answer this question.

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