使用Pandoc将Markdown转换为pdf时如何强制将图像转换为文本 [英] How to force image to text when converting markdown to pdf using pandoc

查看:134
本文介绍了使用Pandoc将Markdown转换为pdf时如何强制将图像转换为文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了 GitHub Wiki -软件包手册-我想进行转换将其转换成精美的pdf手册.但是,我在使用图形时遇到了麻烦-许多图形放置在以下页面之一中,在文本应放置的位置之后很长的位置,这使得文档非常难以阅读.

为此,我基本上遵循了解决方案

Pandoc将LaTeX用于默认情况下创建PDF .

使用外部文件

例如在以下中放置. header.tex:

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

YAML中元数据块:

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

# my markdown header

I made a GitHub wiki - a manual to a software package - and I want to transform it into a beautiful pdf manual. 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;

  2. Convert the markdown files to a single pdf using pandoc:

    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.

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.

Thanks in advance!

解决方案

Pandoc uses LaTeX for PDF creation by default.

Using an external file

Put the following in e.g. 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

Or instead of using a header.tex, you can also embed it in your markdown file's YAML metadata block:

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

# my markdown header

这篇关于使用Pandoc将Markdown转换为pdf时如何强制将图像转换为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆