在DOCX输出中更改Pandoc等宽字体的大小或样式 [英] Changing the Pandoc monospace font size or style in DOCX output

查看:120
本文介绍了在DOCX输出中更改Pandoc等宽字体的大小或样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用降价代码块时,在DOCX文档中产生的等宽字体大小太大.

When using markdown code blocks the resulting monospace font size is too large in DOCX documents.

我可以通过指定自定义的 template.docx 文件来调整段落的字体大小,但是由于某些原因,与大多数其他生成的输出相反,生成的代码块不使用段落样式.

I can adjust the font size of paragraphs by specifying a custom template.docx file, but for some reason the generated code blocks do not use a paragraph style, as opposed to most other generated output.

有什么方法可以

  • 使代码块使用特定的样式,以便可以覆盖 template.docx

要覆盖代码块的DOCX表示中使用的等宽字体吗?

Override the monospace font used in the DOCX representation of code blocks?

已更新以澄清:我正在使用基于注释中先前生成的docx的外部reference.docx.通过修改heading1等的样式,我可以合理控制输出.问题在于生成的等宽文本不使用命名样式,只是带有一些更改的普通"样式.因此,除非我也更改所有常规"文本的大小,否则我无法在模板中进行更改.

Updated to clarify: I am using an external reference.docx based on a previously generated docx as described in the comments. By modifying the styles for heading1 etc I have reasonable control over the output. The problem is that generated monospace text does not use a named style, it is just "normal" with some changes. So I have no way to change it in the template unless I also change the size of all "normal" text.

推荐答案

使用Pandoc 1.17.2和Word 2013我终于找到了一个解决方案,似乎Pandoc的更高版本使用默认情况下隐藏在Word中的链接样式.

Using Pandoc 1.17.2 and Word 2013 I have finally found a solution, it seems later versions of Pandoc uses a linked style that is by default hidden in Word.

第1步:使用

pandoc -o template_1.17.2.docx test.md

test.md包含源代码和您可能要修改的所有其他样式.例如:

Where test.md includes source code and all other styles you may want to modify. For example:

~~~~
this is preformatted source using style "Source Code"
~~~~

~~~ xml
<this> is preformatted source using "KeyworkTok" and "NormalTok"</this>
~~~

在Word中打开template_1.17.2.docx.现在,已使用 hidden 链接样式源代码"对预格式化的源进行了格式化.默认情况下,该样式不会显示在样式预览窗格中,您可以通过单击样式预览面板右下角的带箭头的小方块来配置样式预览窗格来添加它.

Open template_1.17.2.docx in Word. The preformatted source is now formatted using the hidden linked style "Source Code". This style is NOT displayed in the styles preview pane by default, you can add it by configuring the styles preview pane by clicking the tiny square-with-arrow in the bottom right of the styles preview panel.

根据需要修改此样式并保存模板.然后根据此模板生成您的文档:

Modify this style as you wish and save the template. Then generate your document based on this template:

pandoc --reference-docx=template_1.17.2.docx -o mydoc.docx mydoc.md

您现在应该看到源文件在mydoc中的格式正确.

You should now see the source properly formatted in mydoc.

@LinusR建议不同的源样式使用不同的布局样式.我添加了XML作为示例.格式化的XML将使用"KeywordTok"和"NormalTok".

@LinusR suggests that different source styles uses different Layout styles. I have added XML as an example. The formatted XML will use "KeywordTok" and "NormalTok".

这篇关于在DOCX输出中更改Pandoc等宽字体的大小或样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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