更改 lstdefinestyle 似乎不起作用

更改 lstdefinestyle 似乎不起作用

我對使用 LaTeX 還很陌生,我正在嘗試修改預先存在的.latex文件,以便程式碼區塊如下所示:

I'm a code block and I'm pretty!
Important info goes here.

需要注意的是這是一個 LaTeX範本我想與 pandoc 一起使用 - 因此它與包含所有要編輯的文本的另一個文件並行使用(在本例中為 markdown)。我嘗試過引用其他人的模板、複製/貼上等,但我找不到任何適合我的程式碼區塊格式。我將在下面附上到目前為止我所擁有的內容。我正在修改的版本比我見過的其他版本更複雜 - 我實際上正在修改我們在工作中使用的版本,因為它需要更新,所以這裡的一些內容我還不完全理解。總的來說,我對它的外觀很滿意,除了程式碼塊(以及內聯突出顯示,如this)。

TLDR:如何讓程式碼區塊格式真正顯示出來?它從未改變過預設的程式碼區塊格式。幫助!

編輯:經過進一步的探索,如果我添加

\begin{lstlisting}
Test doc
\end{lstlisting}

在此範本中,Test doc顯示我想要的格式。如何讓乳膠文件也格式化來自其他使用的文件的傳入程式碼區塊```

\documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$]{$documentclass$}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{longtable}
\usepackage{amssymb,amsmath}
\usepackage{ifxetex,ifluatex}
 % provides \textsubscript
\usepackage{fixltx2e}
%\usepackage{package/garamond}
%\usepackage[T1]{fontenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{titlesec}
\usepackage[export]{adjustbox}
\usepackage{graphicx}
\usepackage{listings}

\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}

\definecolor{SpecialBlue}{HTML}{2E93CE}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.5,0.5,0.5}

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{SpecialBlue},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,
    breaklines=true,
    captionpos=b,
    keepspaces=true,
    numbers=left,
    numbersep=5pt,
    showspaces=false,
    showstringspaces=false,
    showtabs=false,
    tabsize=2
}

\lstset{style=mystyle}

\let\Oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[1]{\Oldincludegraphics[max width=\linewidth]{#1}}
\titleformat{\section}
{\color{SpecialBlue}\normalfont\Large\bf}
{\color{SpecialBlue}\thesection}{1em}{}

% ~~~~~~~~~~~~~~~~~~~~ HEADER & FOOTER ~~~~~~~~~~~~~~~~~~~~
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhead{}
\fancyfoot{}
\fancyhead[R]{\scriptsize $title$\\$date$}
\fancyfoot[L]{{\scriptsize Proprietary and Confidential}}
\fancyfoot[C]{\raisebox{-0.5\height}{\Oldincludegraphics[width=1in]{Special_logo_2020.png}}}
\fancyfoot[R]{\scriptsize Page \thepage}

% use microtype if available
\textwidth = 6.5in
\oddsidemargin = 0in
\hoffset = 0in
\fancyheadoffset{0in}
\fancyfootoffset{0in}


$if(lhs)$
\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}
$endif$

\ifxetex
  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
              xetex]{hyperref}
\else
  \usepackage[unicode=true]{hyperref}
\fi
%~~~~~~~~~~~~~~~~~~~~~~~~~~ LINKS ~~~~~~~~~~~~~~~~~~~~~~~~~
\hypersetup{breaklinks=true,
            bookmarks=true,
            pdfauthor={$author-meta$},
            pdftitle={$title-meta$},
            colorlinks=false,
            urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,
            linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,
            pdfborder={0 0 0}}
$if(links-as-notes)$
% Make links footnotes instead of hotlinks:
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}
$endif$
$if(strikeout)$
\usepackage[normalem]{ulem}
% avoid problems with \sout in headers with hyperref:
\pdfstringdefDisableCommands{\renewcommand{\sout}{}}
$endif$
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}
\setlength{\emergencystretch}{3em}  % prevent overfull lines
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
$if(numbersections)$
$else$
\setcounter{secnumdepth}{0}
$endif$
$if(verbatim-in-note)$
\VerbatimFootnotes % allows verbatim text in footnotes
$endif$
$for(header-includes)$
$header-includes$
$endfor$
$if(tables)$
\usepackage{ctable}
\usepackage{float} % provides the H option for float placement
$endif$

$if(title)$
\title{$title$}
$endif$
$if(author)$
\author{$for(author)$$author$$sep$ \and $endfor$}
$endif$
$if(date)$
\date{$date$}
$endif$


%~~~~~~~~~~~~~~~~~~~~~~~~~~~ PAGE ~~~~~~~~~~~~~~~~~~~~~~~~
\begin{document}

$if(title)$
\maketitle
$endif$

$for(include-before)$
$include-before$

$endfor$
$if(toc)$
{
\hypersetup{linkcolor=black}
\tableofcontents
}
$endif$
\thispagestyle{fancy}
$body$


$if(natbib)$
$if(biblio-files)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$biblio-files$}

$endif$
$endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$

$endif$
$for(include-after)$
$include-after$

$endfor$
%\ungaramond
\end{document}

答案1

您需要透過新增選項來告訴pandoc使用:listings--listings

pandoc -f markdown -o out.tex --template yourtemplate in.md --listings 

相關內容