annProg / PanBook

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

代码浮动体飘到章节末尾 #28

Closed annProg closed 5 years ago

annProg commented 5 years ago

一章的所有代码浮动体都到了章节末尾,

初步排查是因为 wrap 环境的`tcolorbox 没有设置 breakable,而代码环境的 tcolorbox 设置了 breakable ,给 wrap 加上 breakable 之后能解决问题

或者,都不设置 breakable,但是这样可能会出现大片空白。

annProg commented 5 years ago

有可能是受 longtable 影响 #22

annProg commented 5 years ago
$ grep -i "warn" test.log
Package ctex Warning: Option `fancyhdr' is deprecated.
Package fontspec Warning: Font "FandolSong-Regular" does not contain requested
Package: infwarerr 2016/05/16 v1.4 Providing info/warning/error messages (HO)
Package hyperref Warning: Option `bookmarks' has already been used,
Package listingsutf8 Warning: Package loading is aborted because of missing \pd
Package float Warning: Can't redefine counter variable for codelisting. on inpu
LaTeX Warning: Unused global option(s):
Package fontspec Warning: Font "FandolFang-Regular" does not contain requested
LaTeX Font Warning: Font shape `TU/FandolFang-Regular(0)/m/it' undefined
LaTeX Warning: `h' float specifier changed to `ht'.
Package tcolorbox Warning: The upper box part has become overfull on input line
Package tcolorbox Warning: The upper box part has become overfull on input line
Package tcolorbox Warning: The upper box part has become overfull on input line
Package tcolorbox Warning: The upper box part has become overfull on input line
Package tcolorbox Warning: The upper box part has become overfull on input line
Package tcolorbox Warning: The upper box part has become overfull on input line
Package tcolorbox Warning: The upper box part has become overfull on input line
Package tcolorbox Warning: The upper box part has become overfull on input line
Package tcolorbox Warning: The upper box part has become overfull on input line
LaTeX Warning: Float too large for page by 735.35968pt on input line 559.
LaTeX Warning: `h' float specifier changed to `ht'.
LaTeX Font Warning: Font shape `OMX/cmex/m/n' in size <10.53937> not available
LaTeX Warning: Reference `sec:yaml_metadata_block' on page 2 undefined on input
LaTeX Warning: Float too large for page by 600.4095pt on input line 626.
LaTeX Warning: `h' float specifier changed to `ht'.
LaTeX Warning: `h' float specifier changed to `ht'.
LaTeX Font Warning: Size substitutions with differences
LaTeX Font Warning: Some font shapes were not available, defaults substituted.
LaTeX Warning: There were undefined references.
annProg commented 5 years ago

MWE

\documentclass[fancyhdr,bookmark]{ctexart}
% pandoc版本大于1.15时需要\tightlist
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}

\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{fancyvrb}
\newcommand{\VerbBar}{|}
\newcommand{\VERB}{\Verb[commandchars=\\\{\}]}
\DefineVerbatimEnvironment{Highlighting}{Verbatim}{commandchars=\\\{\}}
% Add ',fontsize=\small' for more characters per line
\newenvironment{Shaded}{}{}

\makeatletter
\@ifpackageloaded{float}{}{\usepackage{float}}
\floatstyle{ruled}
\@ifundefined{c@chapter}{\newfloat{codelisting}{h}{lop}}{\newfloat{codelisting}{h}{lop}[chapter]}
\floatname{codelisting}{代码}
\newcommand*\listoflistings{\listof{codelisting}{代码列表}}
\@ifundefinedcolor{shadecolor}{\definecolor{shadecolor}{rgb}{1.0,1.0,1.0}}
\makeatother

% 解决自动换行问题 https://github.com/annProg/PanBook/issues/26#issuecomment-500458739
\definecolor{shaderulecolor}{rgb}{0.66,0.66,0.66}

\usepackage{tcolorbox}
\tcbuselibrary{most}
\ifcsmacro{Shaded}{
    \let\endShaded\undefined%
    \renewenvironment{Shaded}{\begin{tcolorbox}[
    shadow={0.8mm}{-0.8mm}{0mm}{red!20!green!20!blue!20},
    enhanced,
    boxrule=0.5pt,
    boxsep=-1pt,
    breakable,
    colback=shadecolor,
    colframe=shaderulecolor,
    arc=0.1mm]}{\end{tcolorbox}}
}{}

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

\begin{document}

\begin{itemize}
\tightlist
\item
  安装
  \href{https://www.msys2.org/}{msys2} (
  Linux 及 OS X 请忽略此步骤)
\item
  安装
  \href{http://mirror.ctan.org/systems/texlive/Images/}{texlive}
  2018 或以上版本
\item
  安装
  \href{https://pandoc.org/installing.html}{Pandoc}
  2.7.3 或以上版本
\item
  下载
  \href{https://github.com/lierdakil/pandoc-crossref/releases}{pandoc-crossref}
  对应版本安装到 path 目录下(建议和
  Pandoc 放同一目录)
\end{itemize}

然后下载 PanBook。打开终端( msys2
),假设工作目录为 /d/dev ,执行:

\begin{Shaded}
\begin{Highlighting}[]
1
2
\end{Highlighting}
\end{Shaded}

完成软件安装之后,需要设置环境变量,将
PanBook,TeXLive 及 Pandoc 加入环境变量:

\begin{Shaded}
\begin{Highlighting}[]
1
 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 22 2 2 2 2 2 2 2 2 2 2 2
\end{Highlighting}
\end{Shaded}

完成环境变量设置之后,在任意空目录下执行
panbook
\texttt{\textless{}command\textgreater{}},会自动初始化写作环境,生成示例源码。然后在
src
目录下开始写作。\texttt{\textless{}command\textgreater{}}可以是
book , thesis , slide , cv
。详细帮助信息执行 panbook -h
查看。目录规范见
代码~\ref{lst:panbookdirs}。

\begin{codelisting}

\caption{目录规范}

\hypertarget{lst:panbookdirs}{%
\label{lst:panbookdirs}}%
\begin{Shaded}
\begin{Highlighting}[]
1
2
3
4
5
6
7
8
9
10
11
12
13
\end{Highlighting}
\end{Shaded}

\end{codelisting}

\hypertarget{sec:note}{%
\subsubsection{注意事项}\label{sec:note}}

\begin{itemize}
\tightlist
\item
  Markdown 源码文件需要使用 UTF-8 编码
\item
  Pandoc 扩展的 Markdown
  语法要求在标题前留出一个空行,因此按章节拆分的多个
  Markdown 文件,开头需要空一行,否则
  pandoc 不能正确识别标题
\item
  请勿将正文文件命名为
  \emph{frontmatter.md 或者 }backmatter.md
  ,这 2 个文件有特殊用途
\end{itemize}

\hypertarget{ux4e66ux7c4dux5143ux6570ux636e}{%
\section{书籍元数据}\label{ux4e66ux7c4dux5143ux6570ux636e}}

在 src/metadata.yaml 中使用
\href{http://www.ruanyifeng.com/blog/2016/07/yaml.html}{Yaml
语言}
定义书籍的数据及可用的模板变量,示例见
代码~\ref{lst:metayaml}。

\begin{codelisting}
\caption{Metadata}

\hypertarget{lst:metayaml}{%
\label{lst:metayaml}}%
\begin{Shaded}
\begin{Highlighting}[]
1
2
\end{Highlighting}
\end{Shaded}
\end{codelisting}
\end{document}
annProg commented 5 years ago

以上MWE

  1. 单独取消 fvextrabreakline后问题消失
  2. 单独取消 Shadedtcolorbox中的 breakable 后问题消失
annProg commented 5 years ago

可能是tcolorbox的breakable导致的问题,改用 mdframed