0

as the title states I'm trying to have my json arrays be posted as text in LaTeX. I'm using VSCode as editor.

I'd like to have this json array be posted as a list in LaTeX but can't figure out how to do it.

"tags": [
      "laboris",
      "exercitation",
      "enim",
      "laboris",
      "minim",
      "incididunt",
      "excepteur"
    ],

Here's my LaTeX code:

\documentclass{report}
\begin{document}

\chapter{Chapter 1}

\section{Tags} Here should the tags be posted

\section{friends}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi necante...

\subsection{Friend 1} Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\subsection{Friend 2} Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\subsection{Friend 3} Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\end{document}

Juan Castaño
  • 28,426
Robert
  • 1
  • 1
    I'm not sure if I understand your question, but are you maybe looking for the listings or minted packages? – samcarter_is_at_topanswers.xyz Feb 07 '23 at 10:43
  • Let me try to explain it more clearly. I have code in json and want to display the variables of the code in a clear way in a PDF file (hence why I'm using LaTeX).

    So for example I have a json array of the temperature of the past 7 days. I'd like display the temperature in a nice manner in a PDF file, not the raw json code in a PDF file.

    So what I'm trying to get is to be able to access specific values in my array which is in a json file, and have them called in my LaTeX file.

    – Robert Feb 07 '23 at 10:58
  • Have a look at https://tex.stackexchange.com/questions/222604/ways-to-parse-json-in-latex – samcarter_is_at_topanswers.xyz Feb 07 '23 at 11:01
  • Thanks, I have looked at the post already and fiddled around with it myself, but it still doesn't take the info out of other files, it's still put in hardcoded in the same file, which is the thing I'd like to avoid. – Robert Feb 07 '23 at 11:08
  • 1
    Note that several of the answers in the related question actually do take the json data out of an external file, it is just for demonstration purposes that the contents of the external file is included in the LaTeX code (with the filecontents environment). You can delete that part from the LaTeX file and it would still work the same (i.e., by reading the external .json file). – Marijn Feb 07 '23 at 11:55

1 Answers1

1

enter image description here

\documentclass{report}
\usepackage{listings}
\usepackage{xcolor}

% https://tex.stackexchange.com/questions/83085/how-to-improve-listings-display-of-json-files/83100#83100

\colorlet{punct}{red!60!black} \definecolor{background}{HTML}{EEEEEE} \definecolor{delim}{RGB}{20,105,176} \colorlet{numb}{magenta!60!black}

\lstdefinelanguage{json}{ basicstyle=\normalfont\ttfamily, numbers=left, numberstyle=\scriptsize, stepnumber=1, numbersep=8pt, showstringspaces=false, breaklines=true, frame=lines, backgroundcolor=\color{background}, literate= *{0}{{{\color{numb}0}}}{1} {1}{{{\color{numb}1}}}{1} {2}{{{\color{numb}2}}}{1} {3}{{{\color{numb}3}}}{1} {4}{{{\color{numb}4}}}{1} {5}{{{\color{numb}5}}}{1} {6}{{{\color{numb}6}}}{1} {7}{{{\color{numb}7}}}{1} {8}{{{\color{numb}8}}}{1} {9}{{{\color{numb}9}}}{1} {:}{{{\color{punct}{:}}}}{1} {,}{{{\color{punct}{,}}}}{1} {{}{{{\color{delim}{{}}}}{1} {}}{{{\color{delim}{}}}}}{1} {[}{{{\color{delim}{[}}}}{1} {]}{{{\color{delim}{]}}}}{1}, }

\begin{document}

\chapter{Chapter 1}

\section{Tags} Here should the tags be posted

\lstinputlisting[language=json]{tags.json}

\section{friends}

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisissem. Nullam nec mi et neque pharetra sollicitudin. Praesent imperdiet mi necante...

\subsection{Friend 1} Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\subsection{Friend 2} Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\subsection{Friend 3} Praesent imperdietmi nec ante. Donec ullamcorper, felis non sodales...

\end{document}

David Carlisle
  • 757,742