正如标题所述,我正在尝试将我的 json 数组作为文本发布在 LaTeX 中。我使用 VSCode 作为编辑器。
我想将这个 json 数组作为列表发布在 LaTeX 中,但不知道如何去做。
"tags": [
"laboris",
"exercitation",
"enim",
"laboris",
"minim",
"incididunt",
"excepteur"
],
这是我的 LaTeX 代码:
\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}
答案1
\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}