首页 >> 大全

使用Pandoc和LaTeX从Markdown创建PDF

2023-07-23 大全 24 作者:考证青年

If you've read some of my posts on or , you may know that I'm on a board game. In the game, Chip Shop, you get to run a in 1980s .

如果您已经阅读过我以前在或其他地方发布的一些文章 ,则可能会知道我正在玩棋盘游戏。 在名为Chip Shop的游戏中,您可以在1980年代美国经营一家计算机公司。

As part of the , I'm to open the game as much as . After false , I've on a basic of for most of the game — cards and the .

作为项目的一部分,我正在尝试尽可能开源整个游戏。 经过几次错误的尝试之后,我决定为大多数游戏组件(尤其是纸牌和手册)选择的基本框架。

As the game's uses , the for the game is from the files. I to have pre-boxed and print- of the game, and to this I need to PDFs from the files.

由于游戏的网站使用 ,因此游戏的网站是从文件生成的。 我打算使用该游戏的高级预装盒和自行打印版本,为实现这一目标,我需要从文件生成PDF。

我要完成的工作 (What I'm to )

My ideal is to the PDF files at the same time as the , than the files as them. This rules out my usual for PDF , , as it PDFs from HTML. it's not an is that I want the PDF card to look from the HTML pages, and lacks any kind of view mode to this to CSS rules.

我理想的工作流程是在生成网站的同时生成PDF文件,而不是根据访问者的要求生成文件。 这排除了我通常用于生成PDF的选项 ,因为它从已经生成HTML生成PDF。 不能选择的另一个原因是,我希望PDF卡版本看起来与HTML页面不同,而缺乏任何视图模式功能来完成此任务,而无需诉诸复杂CSS规则。

The file for cards in the Chip Shop game a lot of front for game . Not all are used on every card. For , I need to fit as many cards on an A4 page as —in this case, a 3×3 grid. the pages will need to be -sided, but I haven't that yet.

Chip Shop游戏中卡片的模板文件包含许多面向游戏机制的物质领域 。 并非每张卡都使用全部。 为了方便打印,我需要在A4页面上尽可能多地放入卡片,在这种情况下为3×3网格。 最终,页面需要是双面的,但是我还没有实现。

输入和LaTeX (Enter and LaTeX)

Any for to PDFs from will lead you down the path. is an open-, Swiss Army knife tool that a wide and of input and .

任何在互联网上寻找从生成PDF的解决方案的搜索都将带您进入的道路。 是一种开源的瑞士军刀标记转换工具,它支持越来越多的输入和输出标记格式。

To PDFs with , LaTeX is . LaTeX has its roots in the , and is a and . and LaTeX us to use , and thus to PDFs from a of files and front .

要使用生成PDF,需要LaTeX 。 LaTeX起源于科学研究界,是一个文档声明和布局系统。 和LaTeX的结合使我们可以使用变量,从而从一系列文件生成PDF并支持前端。

the power of and LaTeX, I 't find any way of PDFs (cards) onto one page, when using from files. After much , I on , a line tool for this .

尽管有和LaTeX的强大功能,但我找不到将多个PDF(卡片)组合到一页上的任何方法,尤其是在使用文件中的变量时。 经过大量研究,我选择了 ,它是满足此要求的简单命令行工具。

安装依赖项 ( ) 降价促销 ()

You need no extra for , maybe an and there are so many of those, I you read a few posts to make your .

不需要额外的软件,除了编辑器外,而且其中有很多,我建议您阅读一些 帖子以做出选择。

杰基尔 ()

I'll to use in my taken from my game to the build , but it isn't an part of PDF if you don't need a .

在我的游戏示例中,我将继续使用来说明构建过程,但是,如果您不需要网站,它并不是PDF生成的必要部分。

潘多克 ()

On my Mac, I with , but there are for all .

在Mac上,我在上安装了,但是所有操作系统都有一些选项 。

胶乳 (LaTeX)

There are lots of on the best way to LaTeX, on what you need or to do with it. A full of its tools and can near 2GB, but for most a will be . Read the 's page to find the best for you.

关于安装LaTeX的最佳方法有很多意见,这取决于您需要或打算使用它。 完整安装其常用工具和库可能需要将近2GB,但对于大多数用途而言,只需最少安装即可。 阅读项目的下载页面,以找到最适合您的选择。

For this , we'll be using the , as I use fonts. But you can any that you .

在本教程中,我们将使用引擎,因为我使用自定义字体。 但是您可以选择任何提供所需特定功能的引擎。

杰姆 ()

on how you LaTeX, you may have . (Check by which in the .) If you haven't, then find on here.

根据您安装LaTeX的方式,您可能已经安装了。 (通过在终端中键入which 进行检查。)如果尚未安装 , 请在此处找到有关安装的详细信息 。

构建过程 (The Build )

After some , a bash that I run the best for now. There are , but it works, and I can the later, it to a or Git Hooks.

经过考虑,我目前在本地运行的bash脚本似乎是最好的选择。 有更好的方法,但是它可以工作,我以后可以改进该过程,将其转移到 系统或Git Hooks。

View the bash on .

在上查看bash脚本 。

Let's now step this .

现在让我们逐步完成此脚本。

建立 (Setup)

bundle install
bundle update
rm -dfr _site
rm -dfr pod

These that the Ruby needs to build the are up-to-date, and that we any and print .

这些命令确保构建网站所需的Ruby依赖关系是最新的,并且我们删除了任何现有的网站和打印文件夹。

建立网站 (Build the )

jekyll build
mkdir -p pod/pdf/cards

Next we build the and a for the print of the cards.

接下来,我们建立网站并为卡片的打印版本创建一个文件夹。

从生成PDF ( PDFs from )

Let's a a PDF of each file:

让我们创建一个包含每个文件的PDF版本的文件夹:

for filename in _cards/*.md; do
echo $filename
pandoc --from=markdown+yaml_metadata_block --template _layouts/cards.latex -o pod/pdf/cards/"$(basename "$filename" .md)".pdf --latex-engine=xelatex $filename
done

The every file in the , that the front are . Using the cards.latex (we'll look at that next), the LaTeX a PDF with an name.

该脚本处理目录中的每个文件,确保遵守前字段。 使用正确的LaTeX引擎使用cards.latex模板(我们接下来将介绍),输出具有适当名称的PDF。

LaTeX文件 (The LaTeX File)

A lot of the magic for the card files from takes place in a LaTeX .

从生成名片文件的许多魔术都发生在LaTeX模板中。

View the LaTeX on .

在上查看LaTeX模板 。

LaTeX is new to me, but it isn't too . I'll what I from the LaTeX file (found in /data//.latex) to make the cards work. I for LaTeX files as you edit them.

markdown怎么使用_

LaTeX对我来说是新手,但并不太复杂。 我将说明如何更改默认LaTeX文件(可在/data//.latex )以使卡正常工作。 我建议您使用在编辑LaTeX文件时预览它们。

\usepackage[paperheight=9.0cm,paperwidth=5.7cm,margin=0.5cm]{geometry}
% Set page size
\usepackage{multicol}
% We need column layouts
\usepackage{amsthm,amsmath,amssymb}
\usepackage{graphicx}
% We want images in our layout
\graphicspath{{/Users/chrisward/Workspace/cs_jk/_site/assets/images/cards/}}
% Where are images located
\usepackage{float}
\usepackage[utf8]{inputenc}
\usepackage{fontspec}
\setmainfont{VT323}
% We want to use a custom font installed on our local system, so add that package and select the font

We need a page size, and we'll use later for the costs and of the cards. We're using and fonts, so we need those .

我们需要特定的页面尺寸,稍后我们将使用各列来计算卡的成本和得分。 我们正在使用图形和自定义字体,因此我们需要那些包 。

We're to a that's clear and . Here's how we it:

我们正在尝试创建一个清晰整洁的简单布局。 这是我们如何完成它:

\begin{document}
\begin{flushright}
{$title$}
\end{flushright}
$if(image)$
\begin{figure}[H]
\centering
\includegraphics[height=2cm]{$image$}
\end{figure}
$endif$
\begin{flushleft}
\scriptsize{$body$}
\end{flushleft}
\scriptsize
\begin{tabular}{ l l }
Costs & Scores \\
$if(staffcost)$ Staff: {$staffcost$} $endif$ & $if(loyaltyscore)$ Loyalty: {$loyaltyscore$} $endif$ \\
$if(rdcost)$ RandD: {$rdcost$} $endif$ & $if(profitscore)$ Profit: {$profitscore$} for {$profitlength$} turns $endif$ \\
$if(marketingcost)$ Marketing: {$marketingcost$} $endif$ & $if(longevityscore)$ Longevity: {$longevityscore$} $endif$ \\
$if(longevitycost)$ Longevity: {$longevitycost$} $endif$ &  \\
$if(moneycost)$ Money: {$moneycost$} $endif$ &
\end{tabular}
\begin{flushleft}
$if(specialscore)$
Special: {$specialscore$}
$endif$
\end{flushleft}
\begin{center}
$if(legal)$
\tiny{$legal$}
$endif$
\end{center}
\end{document}

I feel a lot of the above is self for used to code or . We're the of the card, them, font sizes and if there are them, so that the card doesn't end up with empty .

我觉得以上内容对于习惯于编码或标记的任何人来说都是可以自我解释的。 我们正在创建卡的元素,将它们对齐,设置字体大小,并在输出它们之前检查是否有值,以便卡不会以空字段结尾。

We the image to a size and it. The costs and score are in a two- , set with the begin{} and the with the of ls.

我们将图像调整为特定大小并将其居中。 成本和得分值采用两列布局,使用begin{}命令设置,列数量设置为l s。

Single Card

将卡合并到一页上 ( Cards Onto One Page)

We use to a large PDF file each of the PDF cards:

我们使用来创建一个合并每个单独的PDF卡的大型PDF文件:

pdfjam pod/pdf/cards/*.pdf --no-landscape --frame true --nup 3x3 --suffix complete --outfile ./cards.pdf
mv cards pod/cards_complete.pdf

With this , we the :

使用此命令,我们可以具体说明以下内容:

can give an error if you don't into its , so I move the file to where I want it ( that's in the ). Here we could also the PDF files if we don't want them.

如果您不输出到,可能会给出错误,因此我将文件移动到我真正想要的位置(希望将来可以解决)。 在这里,如果我们不想删除单个PDF文件,也​​可以删除它们。

And that's it—we have a and PDF of the game cards.

就是这样-我们有一个网站和游戏卡的可打印PDF。

Cards 9up

运行脚本 ( the )

I run the build with ./build.sh. As there's a lot of image and PDF , it takes about five to ten . I then have a that these to a web .

我使用./build.sh运行构建脚本。 由于图像和PDF处理很多,大约需要五到十分钟。 然后,我有一个单独的脚本将这些文件夹部署到Web服务器。

下一步是什么 (What's Next)

This has taken me a while to get right, but it's now good to move and the and after play .

这个过程花了我一段时间,但现在已经足够好,可以在进行游戏测试后继续前进并完善过程和布局。

I hope you find my and for your . let me know if you have any or .

希望您发现我的研究和实验对您的项目有用。 如果您有任何意见或建议,请告诉我。

翻译自:

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了