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
    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 ... – samcarter_is_at_topanswers.xyz Dec 17 '22 at 15:02

1 Answers1

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