
我有一個 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來自高德納可下載程式頁面,然後運行cweave lp.w
,您會得到一個lp.tex
,用tex lp.tex
(或pdftex lp.tex
) 處理後會給出以下內容作為第一頁:
lp.tex
如果您更改from 的頂部
\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 紙張大小)您將得到以下結果:
特別是對於 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