![将 lstinline 的样式与序言中的列表分开吗?](https://linux22.com/image/432102/%E5%B0%86%20lstinline%20%E7%9A%84%E6%A0%B7%E5%BC%8F%E4%B8%8E%E5%BA%8F%E8%A8%80%E4%B8%AD%E7%9A%84%E5%88%97%E8%A1%A8%E5%88%86%E5%BC%80%E5%90%97%EF%BC%9F.png)
我使用pandoc
,因此我能应用的 tex hack 有点受限。但是,这里有一个例子:我test.md
在 pandoc Markdown 中有这个文档:
---
listings: true # see also https://stackoverflow.com/q/67106641
title: "Some title here"
author: John Doe
date: \today
header-includes: |
\lstset{% for listings
basicstyle=\scriptsize\ttfamily,
breaklines=true,
}
---
# Introduction
Here is some code output, obtained with the `devcon.exe` command line tool:
```
PCI\VEN_8086&DEV_A295&SUBSYS_36E217AA&REV_F0\3&11583659&0&E0
Name: Intel(R) 200 Series Chipset Family PCI Express Root Port #6 - A295
Driver is running.
PCI\VEN_8086&DEV_5912&SUBSYS_36E217AA&REV_04\3&11583659&0&10
Name: Intel(R) HD Graphics 630
Driver is running.
ACPI\ACPI000C\2&DABA3FF&1
Name: ACPI Processor Aggregator
Driver is running.
ACPI\GENUINEINTEL_-_INTEL64_FAMILY_6_MODEL_158_-_INTEL(R)_CORE(TM)_I7-7700T_CPU_@_2.90GHZ\_1
Name: Intel(R) Core(TM) i7-7700T CPU @ 2.90GHz
Driver is running.
```
So ...
使用 转换为 Latex pandoc test.md --listings -s -o test.tex
,我得到:
% Options for packages loaded elsewhere
\PassOptionsToPackage{unicode}{hyperref}
\PassOptionsToPackage{hyphens}{url}
%
\documentclass[
]{article}
\usepackage{amsmath,amssymb}
\usepackage{lmodern}
\usepackage{ifxetex,ifluatex}
\ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{textcomp} % provide euro and other symbols
\else % if luatex or xetex
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1}
\fi
% Use upquote if available, for straight quotes in verbatim environments
\IfFileExists{upquote.sty}{\usepackage{upquote}}{}
\IfFileExists{microtype.sty}{% use microtype if available
\usepackage[]{microtype}
\UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts
}{}
\makeatletter
\@ifundefined{KOMAClassName}{% if non-KOMA class
\IfFileExists{parskip.sty}{%
\usepackage{parskip}
}{% else
\setlength{\parindent}{0pt}
\setlength{\parskip}{6pt plus 2pt minus 1pt}}
}{% if KOMA class
\KOMAoptions{parskip=half}}
\makeatother
\usepackage{xcolor}
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}}
\hypersetup{
pdftitle={Some title here},
pdfauthor={John Doe},
hidelinks,
pdfcreator={LaTeX via pandoc}}
\urlstyle{same} % disable monospaced font for URLs
\usepackage{listings}
\newcommand{\passthrough}[1]{#1}
\lstset{defaultdialect=[5.3]Lua}
\lstset{defaultdialect=[x86masm]Assembler}
\setlength{\emergencystretch}{3em} % prevent overfull lines
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\setcounter{secnumdepth}{-\maxdimen} % remove section numbering
\lstset{% for listings
basicstyle=\scriptsize\ttfamily,
breaklines=true,
}
\ifluatex
\usepackage{selnolig} % disable illegal ligatures
\fi
\title{Some title here}
\author{John Doe}
\date{\today}
\begin{document}
\maketitle
\hypertarget{introduction}{%
\section{Introduction}\label{introduction}}
Here is some code output, obtained with the
\passthrough{\lstinline!devcon.exe!} command line tool:
\begin{lstlisting}
PCI\VEN_8086&DEV_A295&SUBSYS_36E217AA&REV_F0\3&11583659&0&E0
Name: Intel(R) 200 Series Chipset Family PCI Express Root Port #6 - A295
Driver is running.
PCI\VEN_8086&DEV_5912&SUBSYS_36E217AA&REV_04\3&11583659&0&10
Name: Intel(R) HD Graphics 630
Driver is running.
ACPI\ACPI000C\2&DABA3FF&1
Name: ACPI Processor Aggregator
Driver is running.
ACPI\GENUINEINTEL_-_INTEL64_FAMILY_6_MODEL_158_-_INTEL(R)_CORE(TM)_I7-7700T_CPU_@_2.90GHZ\_1
Name: Intel(R) Core(TM) i7-7700T CPU @ 2.90GHz
Driver is running.
\end{lstlisting}
So \ldots{}
\end{document}
最后,使用 获得的 PDF 输出pandoc test.md --listings -o test.pdf
如下所示:
因此,我得到了小字体大小的主要列表\scriptsize
,这正是我想要的 - 但是,现在也用于内联电传打字机/代码,因此内联代码pandoc
是\lstinline
还字体太小了,我可不想要这个。
相反,我希望\lstinline
样式保留正常大小的电传打字字体,并且{lstlisting}
默认使用小(脚本)大小的电传打字字体的环境。
有没有什么方法可以实现这一点,仅通过在 Latex 序言中设置选项即可(因为这几乎是我使用 pandoc 的唯一选项,使用header-includes
YAML 序言中的指令)?
答案1
好的,似乎有一个解决方案 - 使用时listings
,pandoc
可以向代码围栏添加属性``` {style=...}
,这最终会成为{lstlisting}
环境的选项。然后基本上我可以保留字体大小方面的全局样式,并listings
为需要的小字体大小的代码列表定义一个样式(这与尽管定义和使用不同的语言,但所有列表的样式都相同)
这可以应用于 OPtest.md
示例:
---
listings: true # see also https://stackoverflow.com/q/67106641 ; still have to use --listings from the cmdline as well
title: "Some title here"
author: John Doe
date: \today
header-includes: |
```{=latex}
% note that in pandoc, without a code block for latex, all of the lines in header-includes are interpreted as Markdown (so % at start of line is escaped \%, and # at start of line becomes \section)!
% since \lstset is global, do not change font size here, change in separate style
\lstset{% for listings
basicstyle=\ttfamily,
breaklines=true,
}
\lstdefinestyle{lstsmaller}{basicstyle=\scriptsize\ttfamily}
```
---
# Introduction
Here is some code output, obtained with the `devcon.exe` command line tool:
<!-- classes: {.numberLines} becomes \begin{lstlisting}[numbers=left], {.haskell} becomes \begin{lstlisting}[language=Haskell], rest is ignored; however {language=test} becomes \begin{lstlisting}[language=test] and {style=blahblah} becomes \begin{lstlisting}[style=blahblah] ; so then can use \lstdefinestyle -->
<!-- https://stackoverflow.com/q/26549233 ; https://tex.stackexchange.com/q/448456 ; https://stackoverflow.com/q/27000906 ; https://tex.stackexchange.com/q/557548 ; https://tex.stackexchange.com/q/25471 -->
``` {style=lstsmaller}
PCI\VEN_8086&DEV_A295&SUBSYS_36E217AA&REV_F0\3&11583659&0&E0
Name: Intel(R) 200 Series Chipset Family PCI Express Root Port #6 - A295
Driver is running.
PCI\VEN_8086&DEV_5912&SUBSYS_36E217AA&REV_04\3&11583659&0&10
Name: Intel(R) HD Graphics 630
Driver is running.
ACPI\ACPI000C\2&DABA3FF&1
Name: ACPI Processor Aggregator
Driver is running.
ACPI\GENUINEINTEL_-_INTEL64_FAMILY_6_MODEL_158_-_INTEL(R)_CORE(TM)_I7-7700T_CPU_@_2.90GHZ\_1
Name: Intel(R) Core(TM) i7-7700T CPU @ 2.90GHz
Driver is running.
```
So ...
...并使用以下方法处理pandoc test.md --listings -o test.pdf
结果:
...这就是我想要的。
编辑:这是在 pandoc 2.11.4 上