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

包含浮动体和longtable的页面内容溢出 #22

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

包含浮动体和longtable的页面内容溢出 #22

annProg opened this issue Jun 3, 2019 · 9 comments

Comments

@annProg
Copy link
Owner

annProg commented Jun 3, 2019

\documentclass[fancyhdr,bookmark]{ctexbook}
\setmainfont{DejaVu Sans} 	% 設定英文字型
\setromanfont{DejaVu Sans} 	% 字型
\setmonofont{DejaVu Sans Mono}

\usepackage{ifxetex,ifluatex}
\providecommand{\tightlist}{%
  \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}

\usepackage{tikz} % Required for drawing custom shapes
\usepackage[yyyymmdd,hhmmss]{datetime}
\ctexset{today=small}

\usepackage{listings}
\newcommand{\passthrough}[1]{\colorbox{lightgray}{#1}}

\ifxetex
  \usepackage[setpagesize=false, % page size defined by xetex
              unicode=false, % unicode breaks when used with xetex
              xetex]{hyperref}
\else
  \usepackage[unicode=true]{hyperref}
\fi
\hypersetup{breaklinks=true,
            bookmarks=true,
            pdfauthor={John Mike},
            pdftitle={PanBook使用手册},
            colorlinks=true,
            urlcolor=blue,
            linkcolor=magenta,
            pdfborder={0 0 0}}
\urlstyle{same}  % don't use monospace font for urls

\usepackage{longtable,booktabs}
\usepackage{graphicx,grffile}
\makeatletter
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
\makeatother


\title{PanBook使用手册\\\vspace{0.5em}{\large 用Markdown和Pandoc写作}}
\author{John Mike}
\date{\today}

\usepackage{geometry}
\newcommand{\devicepc}{
	\geometry{
		top=1in,
		inner=1in,
		outer=1in,
		bottom=1in,
		headheight=3ex,
		headsep=2ex
	}
}
\devicepc

\definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
\definecolor{lightgray}{rgb}{0.97,0.97,1}
\renewcommand{\passthrough}[1]{\colorbox{lightgray}{#1}}
\newfontfamily\code{Courier New}

\lstset{
	basicstyle=\small\linespread{1}\code,
	keywordstyle=\color[rgb]{0.13,0.29,0.53}\textbf,
	commentstyle=\color{gray},
	identifierstyle=\color[rgb]{0.00,0.00,0.00},
	stringstyle=\color[rgb]{0.31,0.60,0.02},
	rulesepcolor=\color{red!20!green!20!blue!20},
	backgroundcolor=\color[rgb]{0.97,0.97,0.97},
	tabsize=4,
	breaklines=tr,
	showstringspaces=false,
}
\renewcommand{\lstlistingname}{代码}
\usepackage{keyval}
\newlength\Colsep
\setlength\Colsep{10pt}
\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
\frontmatter
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\mainmatter
    % 在此命令之后的页码为阿拉伯数字
    % 以下为正文
\hypertarget{panbookux624bux518c}{%
\chapter{PanBook手册}\label{panbookux624bux518c}}

\passthrough{\lstinline!PanBook!}是基于\passthrough{\lstinline!Pandoc!}和\passthrough{\lstinline!LaTeX!}开发的一个工具,提供了一些开箱即用的书籍,论文,幻灯片及简历模板,以及一些\passthrough{\lstinline!lua filter!}扩展。用来更方便的使用\passthrough{\lstinline!Pandoc!}将\passthrough{\lstinline!Markdown!}转换为\passthrough{\lstinline!PDF!}或\passthrough{\lstinline!epub!}格式。

\hypertarget{ux5febux901fux5f00ux59cb}{%
\section{快速开始}\label{ux5febux901fux5f00ux59cb}}

以\passthrough{\lstinline!Windows 10!}为例,演示如何使用。

\hypertarget{ux5b89ux88c5ux4f9dux8d56ux8f6fux4ef6}{%
\subsection{安装依赖软件}\label{ux5b89ux88c5ux4f9dux8d56ux8f6fux4ef6}}

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

\hypertarget{ux5b89ux88c5panbook}{%
\subsubsection{安装PanBook}\label{ux5b89ux88c5panbook}}

\passthrough{\lstinline!PanBook!}是一组\passthrough{\lstinline!Shell!}脚本,直接下载到任意目录即可。打开终端(\passthrough{\lstinline!msys2!}),假设工作目录为\passthrough{\lstinline!/d/!},执行代码~\ref{lst:gitclone}。

\begin{lstlisting}[language=bash, caption=安装PanBook, label=lst:gitclone, float=htbp]
$ cd /d/
$ git clone https://github.com/annProg/PanBook
\end{lstlisting}

\hypertarget{ux8bbeux7f6eux73afux5883ux53d8ux91cf}{%
\subsubsection{设置环境变量}\label{ux8bbeux7f6eux73afux5883ux53d8ux91cf}}

需要将本项目,\passthrough{\lstinline!texlive!}及\passthrough{\lstinline!Pandoc!}加入环境变量,如代码~\ref{lst:setpath}所示。

\begin{lstlisting}[language=bash, caption=设置环境变量, label=lst:setpath, float=htbp]
$ tail -n 1 ~/.bashrc
export PATH=$PATH:/d/texlive/2018/bin/win32:/d/dev/PanBook:/c/Users/myname/AppData/Local/Pandoc
\end{lstlisting}

\hypertarget{ux5f00ux59cbux4f7fux7528}{%
\subsection{开始使用}\label{ux5f00ux59cbux4f7fux7528}}

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

\begin{lstlisting}[language=bash, caption=目录规范, label=lst:panbookdirs, float=htbp]
.
├── templates                               # 自定义模板
├── styles                                  # 自定义风格
├── extensions                              # 自定义扩展
├── fonts                                   # 自定义字体
├── build                                   # 电子书构建目录
├── src                                     # Markdown源码目录
│   └── images                              # 源码涉及插图目录
│   └── metadata.yaml                       # 书籍元数据文件
│   └── frontmatter.md                      # 前言文件
│   └── backmatter.md                       # 后记文件
│   └── 100-chapter1.md                     # 正文,命名须保证能按正确章节顺序列出
│   └── 200-chapter2.md            
\end{lstlisting}

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

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

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

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

\begin{lstlisting}[caption=Metadata, label=lst:metayaml, float=htbp]
---
title: PanBook使用手册
subtitle: 用Pandoc和Markdown写作
author:          # 作者(数组)
  - John Mike
homepage: https://github.com/annProg/PanBook
header-includes:
  - \usepackage{cleveref}
  - \usepackage{float}
...
\end{lstlisting}


查看模板文件,可以获取模板支持的所有变量(形如\passthrough{\lstinline!$var$!})。也可以通过修改模板来添加自定义的变量。


\hypertarget{ux5199ux4f5cux5de5ux5177}{%
\section{写作工具}\label{ux5199ux4f5cux5de5ux5177}}

推荐使用 \href{https://code.visualstudio.com/}{Visual Studio
Code}。一些有用的插件见表~\ref{tbl:vscodeplugin}。

\hypertarget{tbl:vscodeplugin}{}
\begin{longtable}[]{@{}lc@{}}
\caption{\label{tbl:vscodeplugin}推荐插件}\tabularnewline
\toprule
插件 & 功能\tabularnewline
\midrule
\endfirsthead
\toprule
插件 & 功能\tabularnewline
\midrule
\endhead
Markdown Preview & Markdown实时预览\tabularnewline
\LaTeX~language support & \LaTeX 语言高亮\tabularnewline
All Autocomplete & 自动补全(支持单词补全)\tabularnewline
\bottomrule
\end{longtable}

使用代码~\ref{lst:vscodeMsys}
将终端改为\passthrough{\lstinline!msys2!}的\passthrough{\lstinline!bash!}。

\begin{lstlisting}[caption={VS Code使用msys2}, label=lst:vscodeMsys, float=htbp]
{
    "terminal.integrated.shell.windows": "D:\\msys64\\usr\\bin\\bash.exe",
    "terminal.integrated.shellArgs.windows": ["-l"],
    "terminal.integrated.env.windows": {
        "CHERE_INVOKING": "1",
        "MSYSTEM": "MINGW64",
    },
    "git.postCommitCommand": "push",
    "git.path": "D:\\msys64\\git-vscode.bat",
    "editor.insertSpaces": false,
    "editor.detectIndentation": false,
}  
\end{lstlisting}

%\begin{help}

通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。

通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。

通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。

通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。

通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。

通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。

通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。

通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。

通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。

通过 VS Code
Tasks,使用\passthrough{\lstinline!PanBook!}部分编译参数\passthrough{\lstinline!--part=md文件名!},可用快捷键(ctrl+shift+b)编译当前Markdown源文件。

%\end{help}

\backmatter

\end{document}
@annProg
Copy link
Owner Author

annProg commented Jun 3, 2019

因为listingsfloat=htbp导致

modules/boo/book.sh

# 以下2行是干嘛的?
sed -i -E "/begin\{lstlisting.*label.*\]/ s/caption=(.*)?,\s*label=(.*)\]/caption=\1, label=\2, float=htbp\]/" $TEX_OUTPUT
sed -i -E "/begin\{lstlisting.*label.*\]/ s/\[label=(.*)?\]/\[label=\1, caption=\1, float=htbp\]/" 

@annProg annProg closed this as completed in 30368fa Jun 3, 2019
@annProg
Copy link
Owner Author

annProg commented Jun 4, 2019

删除 float=htbp 之后listings存在跨页问题。
image

参见:https://tex.stackexchange.com/questions/88134/stop-listings-going-over-page-breaks

@annProg annProg reopened this Jun 4, 2019
@muzimuzhi
Copy link

可以加上 latex2e 项目里的相关 bug report:

虽然那个 issue 里提供的 MWE,无关信息也非常多。

@annProg
Copy link
Owner Author

annProg commented Jun 4, 2019

可以加上 latex2e 项目里的相关 bug report:

虽然那个 issue 里提供的 MWE,无关信息也非常多。

非常感谢!

annProg added a commit that referenced this issue Jun 4, 2019
annProg added a commit that referenced this issue Jun 4, 2019
@annProg annProg changed the title ctexbook换页错误 包含浮动体和longtable的页面内容溢出 Jun 5, 2019
@annProg
Copy link
Owner Author

annProg commented Jun 6, 2019

多个float复现代码

\documentclass{article}
\usepackage{longtable}

% helper pkg
\usepackage[pass, showframe]{geometry}
\usepackage{lipsum}
\usepackage{listings}

\begin{document}
\begin{lstlisting}[float=htbp]
hello
\end{lstlisting}

\begin{figure}[t]
  a\\b\\c\\d
\end{figure}
\begin{lstlisting}[float=htbp]
hello2
\end{lstlisting}

\lipsum[1] % optional
\begin{lstlisting}[float=htbp]
hello3
\end{lstlisting}

\begin{longtable}{l}
  cell
\end{longtable}
\begin{lstlisting}[float=htbp]
hello4
\end{lstlisting}

\lipsum
\end{document}

@annProg
Copy link
Owner Author

annProg commented Jun 6, 2019

jgm/pandoc#5557

@annProg
Copy link
Owner Author

annProg commented Jul 16, 2019

https://www.latex-project.org/cgi-bin/ltxbugs2html.new?pr=tools/3512 的patch,对以下 MWE 不生效(longtable前后都有figure)

\documentclass[a4paper,12pt]{article}
\usepackage{longtable}
\usepackage{caption}
\newcommand{\baz}{foo foo foo foo foo foo foo foo}
\newcommand{\qux}{\baz\baz\baz\baz\baz\baz\baz\baz}
\begin{document}

\begin{figure}
\caption{Test Figure}
\vspace{10cm}
\end{figure}

\begin{longtable}{llll}
bar & bar & bar & bar
\end{longtable}

\baz


\begin{figure}
\caption{Test Figure 2}
\vspace{10cm}
\end{figure}

\qux\qux\qux\qux\qux\qux\qux\qux
\end{document}

@annProg
Copy link
Owner Author

annProg commented Jul 16, 2019

latex3/latex2e#158

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

2 participants