2

I use pandoc, so I'm a bit limited in the tex hacks I can apply. However, here is an example: I have this document, test.md, in 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 ...

Convert to Latex using pandoc test.md --listings -s -o test.tex, I get:

% 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}

And finally, the PDF output, obtained with pandoc test.md --listings -o test.pdf, looks like this:

pdf output

So, got my main listing in small \scriptsize font size, which is what I wanted - however, now pandoc uses \lstinline for the inline teletype/code as well, and so the inline code is also small font size, which I do not want.

Instead, I would like the \lstinline style to keep the normal size teletype font, and the {lstlisting} environment with small (script) size teletype font by default.

Is there any way I can achieve this, solely by setting options in the Latex preamble (as that is pretty much the only option I have with pandoc, using the header-includes directive in the YAML preamble)?

sdbbs
  • 245

1 Answers1

2

OK, seems there is a solution - when using listings in pandoc, one can add attributes to the code fence ``` {style=...}, and this ends up as options to {lstlisting} environment. Then basically I can leave the global style as-is in terms of fontsize, and define a listings style with a small fontsize for those code listings where I need that (which is pretty much the same approach as in Listings all in the same style although different languages are defined and used )

This can be applied to the OP test.md example:

---
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 -->

PCI\VEN_8086&amp;DEV_A295&amp;SUBSYS_36E217AA&amp;REV_F0\3&amp;11583659&amp;0&amp;E0
    Name: Intel(R) 200 Series Chipset Family PCI Express Root Port #6 - A295
    Driver is running.
PCI\VEN_8086&amp;DEV_5912&amp;SUBSYS_36E217AA&amp;REV_04\3&amp;11583659&amp;0&amp;10
    Name: Intel(R) HD Graphics 630
    Driver is running.
ACPI\ACPI000C\2&amp;DABA3FF&amp;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 ...

... and processing this with pandoc test.md --listings -o test.pdf results with:

pdf output

... which is what I wanted.

EDIT: this is on pandoc 2.11.4

sdbbs
  • 245