annProg / PanBook

Pandoc LaTeX,Epub模板,用于生成书籍,幻灯片(beamer),简历,论文等(cv, thesis, ebook,beamer)
BSD 3-Clause "New" or "Revised" License
263 stars 28 forks source link

取消listings作为默认代码高亮 #26

Open annProg opened 5 years ago

annProg commented 5 years ago

由于listings有一些语言不支持,默认改为使用pandoc代码高亮。

https://github.com/annProg/PanBook/tree/master/test/highlight

annProg commented 5 years ago

minted支持mathescape,考虑要不要加入minted

annProg commented 5 years ago

默认的代码高亮不支持自动换行,可以pass了。

annProg commented 5 years ago

以上问题可以解决

\usepackage{fvextra}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaklines,commandchars=\\\{\}}

see https://tex.stackexchange.com/questions/179926/pandoc-markdown-to-pdf-without-cutting-off-code-block-lines-that-are-too-long

annProg commented 5 years ago

默认代码高亮加pandoc-crossrefcodelistings环境,存在长代码分页问题

annProg commented 5 years ago

使用minted要求有python环境并且安装Pygments,不太适合作为默认选项。

annProg commented 5 years ago

fvextra能解决换行,字号问题 https://mirrors.tuna.tsinghua.edu.cn/CTAN/macros/latex/contrib/fvextra/fvextra.pdf

annProg commented 5 years ago

pandoc 定义了一些命令去高亮代码,比如 NormalOK,这些命令中的连续字符串即使用了breaklines=true, breakanywhere=true 也不能自动换行,该考虑放弃了。

另外,listings支持的高亮语言有限,可能minted是最好的选择,mintedfvextra是同一个作者,很多选项都是通用的,能自动换行,能改字号,也能换页

以下代码,pandoc定义命令外的无空格长字符串可以换行,\NormalTok包裹的无空格字符串无法自动换行(中文可以正常换行)。

\begin{Highlighting}[numbers=left,breaklines=true,breakanywhere=true,breakbefore=C,firstnumber=100,]
\FunctionTok{# Chapter 1}
LongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCode

\NormalTok{LongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCodeLongCode}

\NormalTok{长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码长代码}
annProg commented 5 years ago

跨页问题

  1. listings无float选项时可以正常跨页
  2. 原生高亮及minted会被pandoc-crossref增加codelistings环境,是一个float环境,存在跨页问题
annProg commented 5 years ago

https://tex.stackexchange.com/questions/175650/how-to-allow-page-break-inside-a-float-environment

Floats cannot be broken across pages—they will continue to float until they fit a page or the document ends, whichever comes first. It appears (from usage of !h, which is not recommended, by the way) that you're trying to absolutely position this float anyway.

看来长代码只能手动分成多个短代码块了