简体   繁体   English

使用pandoc将markdown转换为pdf时如何强制图像到文本

[英]How to force image to text when converting markdown to pdf using pandoc

I made a GitHub wiki - a manual to a software package - and I want to transform it into a beautiful pdf manual. 我制作了一个GitHub wiki - 一个软件包的手册 - 我想把它变成一本漂亮的pdf手册。 However, I have some trouble with figures - many of them are put in one of the following pages, much after the place in the text where it should be, what turns the document very difficult to read. 但是,我在使用数字方面遇到了一些麻烦 - 其中很多都放在下面的一个页面中,大部分都放在文本中应该是的位置之后,是什么让文档很难阅读。

To do so, I followed basically what was suggested here . 为此,我基本上遵循了这里建议的内容。 Basically the idea is to: 基本上这个想法是:

  1. Clone the GitHub wiki; 克隆GitHub wiki;

  2. Convert the markdown files to a single pdf using pandoc: 使用pandoc将markdown文件转换为单个pdf:

    pandoc -s FirstSection.md FirstSection.md FirstSection.md -o manual.pdf pandoc -s FirstSection.md FirstSection.md FirstSection.md -o manual.pdf

What happens is that I have a sequence of short sentences, each one followed by a figure (take a look here for example). 会发生什么事情,我有一系列短句,每个句子后跟一个数字(例如,看看这里 )。 When I open the resulting pdf, each figure is not right after the sentence that precedes it in the wiki, but rather I have a sequence of many sentences and a sequence figures in a row, but it makes the document really hard to follow. 当我打开生成的pdf时,每个数字都不在wiki之前的句子之后,而是我有一系列的句子和连续的序列图,但它使文档很难遵循。

Is there a way of forcing the images to be right after a piece of text where they are placed, and avoid having the text that comes after it before the image? 有没有办法强制图像在放置它们的文本后面,并避免在图像之前有文字?

I have found some solutions for Rmarkdown, but they did not work for me. 我找到了一些Rmarkdown的解决方案,但它们对我不起作用。

Thanks in advance! 提前致谢!

Pandoc uses LaTeX for PDF creation by default . Pandoc 默认使用LaTeX进行PDF创建

Using an external file 使用外部文件

Put the following in eg header.tex : 以下内容放在header.tex

\makeatletter
\def\fps@figure{h}
\makeatother

Or alternatively, the following : 或者, 以下内容

\usepackage{float}
\let\origfigure\figure
\let\endorigfigure\endfigure
\renewenvironment{figure}[1][2] {
    \expandafter\origfigure\expandafter[H]
} {
    \endorigfigure
}

Then use: 然后使用:

pandoc input.md --include-in-header header.tex -o output.pdf

Using only a markdown file 仅使用markdown文件

Or instead of using a header.tex , you can also embed it in your markdown file's YAML metadata block : 或者,您也可以将其嵌入到markdown文件的YAML元数据块中 ,而不是使用header.tex

---
header-includes: |
  \makeatletter
  \def\fps@figure{h}
  \makeatother
---

# my markdown header

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM