Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
annProg opened this issue Jun 10, 2019 · 9 comments
Open

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

annProg opened this issue Jun 10, 2019 · 9 comments

Comments

@annProg
Copy link
Owner

annProg commented Jun 10, 2019

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

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

@annProg annProg changed the title 使用pandoc代码高亮 取消listings作为默认代码高亮 Jun 10, 2019
@annProg
Copy link
Owner Author

annProg commented Jun 10, 2019

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

@annProg
Copy link
Owner Author

annProg commented Jun 10, 2019

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

@annProg
Copy link
Owner Author

annProg commented Jun 10, 2019

以上问题可以解决

\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 added a commit that referenced this issue Jun 10, 2019
@annProg
Copy link
Owner Author

annProg commented Jun 10, 2019

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

@annProg
Copy link
Owner Author

annProg commented Jun 10, 2019

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

@annProg
Copy link
Owner Author

annProg commented Jun 10, 2019

@annProg
Copy link
Owner Author

annProg commented Jun 10, 2019

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 added a commit that referenced this issue Jun 10, 2019
@annProg
Copy link
Owner Author

annProg commented Jun 11, 2019

跨页问题

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

@annProg
Copy link
Owner Author

annProg commented Jun 11, 2019

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.

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

annProg added a commit that referenced this issue Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant