1

How do I properly format and highlight a docker-compose.yml file when including a code snippet into a latex document.

I want to do something like:

\documentclass{article}
\usepackage{listings}
\lstset{language=YAML}

\begin{document}

\lstinputlisting{docker-compose.yml}

\end{document}

to import the following docker-compose.yml.

version: "3.7"

services:
  foo:
    image: hello-world

How do I add syntax highlighting for *.yaml/*.yml files?

I am aware of this answer to format a yaml snippet. I want to know how to do the same with an imported yaml file.

1
  • 1
    Please make a compilable minimal working example which shows us your class, the relevant packages and a short test document. Please also include what the result should look like - formatted properly can mean many things ... Dec 17, 2022 at 15:02

1 Answer 1

1

You can use the same approach as in the answer you linked to (don't forget to also load the xcolor package):

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}

\lstdefinestyle{yaml}{
     basicstyle=\color{blue}\footnotesize,
     rulecolor=\color{black},
     string=[s]{'}{'},
     stringstyle=\color{blue},
     comment=[l]{:},
     commentstyle=\color{black},
     morecomment=[l]{-}
 }


\begin{document}

\lstinputlisting[style=yaml]{docker-compose.yml}

\end{document}

enter image description here

You must log in to answer this question.

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