我对使用 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
显示我想要的格式。如何让 latex 文档也格式化来自使用 的其他文件的传入代码块```
?
\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