如何设置 CWEB 文档的页面尺寸?

如何设置 CWEB 文档的页面尺寸?

我有一个 CWEB 文件,我想更改页面尺寸。我知道如何在普通的 TeX 文档中执行此操作,而且对我来说,它总是很有效。如果我在 CWEB 文件中执行相同的操作(更改 hsize、偏移量等),我的边距和位置就会完全混乱。

我想在 A4 纸上输出。我的 pdftex 将最终页面尺寸设置为 A4,所以这不是问题。问题在于 CWEB 是为信纸输出而设计的,因此副本不居中。

我尝试在 Knuth 的 Stanford Graphbase 中寻找解决方案,因为它是一堆以书籍格式发布的 CWEB 程序,所以他一定做了一些事情来改变页面尺寸。然而,他在互联网上提供的资源是为字母输出而制作的,所以它们毫无帮助。有什么想法吗?

到目前为止,我在 CWEB 文件的开头添加了以下代码(顺便说一下,此代码在纯 TeX 文件中有效):

\newdimen\pagewidth   \pagewidth=210mm
\newdimen\pageheight  \pageheight=297mm

\hsize=13cm

\hoffset=\pagewidth
\advance\hoffset by-\hsize
\hoffset=.5\hoffset
\advance\hoffset by-1in

\voffset=\pageheight
\advance\voffset by-\vsize
\voffset=0.5\voffset
\advance\voffset by-1in

答案1

这在 CWEB 手册中有记录(您可以通过调用texdoc cweb打开 DVI 文件来打开,或者在线阅读 PDF 格式), 在附录 C:如何使用 CWEB 宏(第 25 页),第 4 点。

诀窍在于,在设置\pagewidth(默认 6.5 英寸)、\pageheight(默认 8.7 英寸) 或\fullpageheight(默认 9 英寸) 中的任何一个之后,您需要说\setpage

如果你改变了其中任何数量,你应该在做出改变之后立即调用宏 \setpage。


例子:如果您下载lp.w来自 Knuth 的可下载程序页面,并运行cweave lp.w,您将得到一个lp.tex,用tex lp.tex(或pdftex lp.tex)处理后将得到以下第一页:

lp-默认

如果你改变顶部lp.tex

\input cwebmac
\datethis

\input cwebmac
\pagewidth=3.25in % The default is 6.5in
\pageheight=4.35in % The default is 8.7in
\fullpageheight=4.5in % The default is 9in
\setpage
\datethis

(将所有内容减半),然后(如果不更改 pdf 纸张大小)您将获得以下内容:

lp-减半


具体来说,对于 A4 纸,如果您想保持与信纸相同的边距(这可能没有多大意义,但是一种选择),那么您可以将文件\input cwebmac顶部的更改.tex为(如果您使用pdftex):

\input cwebmac
\pdfpagewidth=210mm
\pdfpageheight=297mm
\pagewidth= 159.2mm % The default is 6.5in for 8.5in width, so for A4 this is 210mm - 2in
\pageheight=238.58mm % The default is 8.7in for 11in height, so for A4 this is 297mm - 2.3in
\fullpageheight=246.2mm % The default is 9in for 11in height, so for A4 this is 297mm - 2in
\setpage

如果您想保持布局(文本宽度、换行符等)与信纸相同,但将其挤压并居中在 A4 纸上(如 Igor 的回答中所建议的),那么您当然不需要做任何特定的事情,cwebmac您可以在任何地方使用相同的代码块:您只需调整\pdfhorigin:默认值为1in(=(8.5in - 6.5in)/2)。只需将其添加到文件顶部,不要更改任何其他内容:

\pdfpagewidth=210mm
\pdfpageheight=297mm
\pdfhorigin=\dimexpr (210mm-6.5in)/2
\pdfvorigin=\dimexpr (297mm-9in)/2

相关内容