I have a JSON code snippet that I like to include into my LaTeX document:
"builders": [ { "type": "test", "image": "ubuntu:latest", "changes": [ "EXPOSE 123 456", "CMD [\"/tmp/entrypoint.sh\"]" ], "commit": true } ] I'd like to highlight it the similarly to how Visual Studio Code highlights it:
- Same colors for keywords
- Same amount of indentation
- Preferably these vertical lines if possible
- Line numbers on the left side (not shown in the image)
- A single frame around the final code block
- No Black background color, obviously
I heard about the minted as it seems to be a good choice for this task. However, my attempts look horrible, not close at all to the picture at all.
I had lot's of problems with highlighting the key and values differently, because both seem to be interpreted as string - and would therefore be highlighted in the same color when the string color is specified.
Also I don't want to write down every value on the right side as keyword down... There must be a way to automatically highlight the key and the value differently, based of some logic. Also no idea at all about the vertical lines. Also could not get the line numbers working. Furthermore the font looks totally different, is there a way to use a similar looking one?
Since I couldn't get a proper result with the minted package I also played around with the listings package, still does not look good. This is what I got so far:
\definecolor{keycolor}{HTML}{569CD6} \definecolor{valuecolor}{HTML}{FF0000} \lstdefinelanguage{js}{ keywords={type,image,changes, CMD, WORKDIR, EXPOSE, builders, commit}, keywordstyle=\color{keycolor}\bfseries, keywords=[2]{test}, keywordstyle=[2]\color{valuecolor}\bfseries, sensitive=false, morecomment=[s]{/*}{*/} } \lstset{ language=js, frame=single, extendedchars=true, basicstyle=\footnotesize\ttfamily, showstringspaces=false, showspaces=false, tabsize=2, breaklines=true, showtabs=false } and then:
\begin{lstlisting} "builders": [ { "type": "test", "image": "ubuntu:latest", "changes": [ "EXPOSE 123 456", "CMD [\"/tmp/entrypoint.sh\"]" ], "commit": true } ] \end{lstlisting} Which looks like this:
How can I make it as close to the VSCode example as possible? I am fine with using whatever package works best for this task.



listingsbecause I did read about it here: tex.stackexchange.com/questions/336919/… Yeah, minted might be the better option. I am fine with any solution that comes as close as possible to the example picture. I updated my question.