如何將序言中的文檔字體大小從 11pt 更改為 12pt?

如何將序言中的文檔字體大小從 11pt 更改為 12pt?

如果文件看起來像這樣

\documentclass[11pt]{report}
\begin{document}
my report here
\end{document}

是否可以在序言中插入一條命令,將文檔大小更改為12pt?你可能會問,為什麼不\documentclass[11pt]{report}改為\documentclass[12pt]{report}?這是因為我需要在某些條件下更改大小,我將在序言中檢查這一點。

\documentclass由於其他原因,很難添加有關線路的條件本身。所以我正在尋找這樣的東西

\documentclass[11pt]{report}

\ifdefined\HCode
 \changeDocumentclassDefaultFontTo{12pt}
\fi

\begin{document}
my report here
\end{document}

再說一遍,我知道我能做到

\ifdefined\HCode
   \documentclass[12pt]{report}
\else
   \documentclass[11pt]{report}
\fi

\begin{document}
my report here
\end{document}

但我不想執行上述操作,因為原始 Latex 文件是自動生成的,而且我使用的軟體不喜歡上述文件,如果我這樣做,我將無法在該軟體中使用它。但我可以輕鬆修改前導碼,而不影響再次使用該檔案。

更新

我無法編譯以下答案之一。它在 pdflatex、lualatex 和 tex4ht 中給出錯誤。我不知道我是否應該做點別的事情。

\documentclass[11pt]{report}

%\ifdefined\HCode  %commented to see if will compile in lualatex
  \let\small\undefined
  \let\footnotesize\undefined
  \let\scriptsize\undefined
  \let\tiny\undefined
  \let\large\undefined
  \let\Large\undefined
  \let\LARGE\undefined
  \let\huge\undefined
  \input{size12.clo}
%\fi

\begin{document}
my report here
\end{document}

現在lualatex foo.tex給出

lualatex foo.tex
This is LuaTeX, Version 1.0.4 (TeX Live 2017) 
 restricted system commands enabled.
(./foo.tex
LaTeX2e <2017-04-15>
(using write cache: /home/me/.texlive2017/texmf-var/luatex-cache/generic)(using
 read cache: /usr/local/texlive/2017/texmf-var/luatex-cache/generic /home/me/.t
exlive2017/texmf-var/luatex-cache/generic)
luaotfload | main : initialization completed in 0.124 seconds
Babel <3.15> and hyphenation patterns for 1 language(s) loaded.
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/report.cls
Document Class: report 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/size11.clo(load luc: /home/m
e/.texlive2017/texmf-var/luatex-cache/generic/fonts/otl/lmroman10-regular.luc))
) (/usr/local/texlive/2017/texmf-dist/tex/latex/base/size12.clo
! You can't use `\spacefactor' in vertical mode.
\@->\spacefactor 
                 \@m {}
l.54 \normalsize

? 

>which lualatex 
/usr/local/texlive/2017/bin/x86_64-linux/lualatex

記錄檔

>cat foo.log
This is LuaTeX, Version 1.0.4 (TeX Live 2017)  (format=lualatex 2017.11.10)  17 FEB 2018 17:43
 restricted system commands enabled.
**foo.tex
(./foo.tex
LaTeX2e <2017-04-15>
Lua module: luaotfload-main 2017/01/29 2.80001 OpenType layout system.
Lua module: lualibs 2017-02-01 2.5 ConTeXt Lua standard libraries.
Lua module: lualibs-extended 2017-02-01 2.5 ConTeXt Lua libraries -- extended co
llection.(using write cache: /home/me/.texlive2017/texmf-var/luatex-cache/generi
c)(using read cache: /usr/local/texlive/2017/texmf-var/luatex-cache/generic /hom
e/me/.texlive2017/texmf-var/luatex-cache/generic)
luaotfload | conf : Root cache directory is /home/me/.texlive2017/texmf-var/luat
ex-cache/generic/names.
luaotfload | init : Loading fontloader “fontloader-2017-02-11.lua” from kpse
-resolved path “/usr/local/texlive/2017/texmf-dist/tex/luatex/luaotfload/fontl
oader-2017-02-11.lua”.
Lua-only attribute luaotfload@state = 1
Lua-only attribute luaotfload@noligature = 2
Lua-only attribute luaotfload@syllabe = 3
luaotfload | init : Context OpenType loader version “3.027”
Inserting `luaotfload.node_processor' at position 1 in `pre_linebreak_filter'.
Inserting `luaotfload.node_processor' at position 1 in `hpack_filter'.
Inserting `luaotfload.define_font' at position 1 in `define_font'.
Lua-only attribute luaotfload_color_attribute = 4
luaotfload | conf : Root cache directory is /home/me/.texlive2017/texmf-var/luat
ex-cache/generic/names.
Inserting `luaotfload.aux.set_sscale_dimens' at position 1 in `luaotfload.patch_
font'.
Inserting `luaotfload.aux.patch_cambria_domh' at position 2 in `luaotfload.patch
_font'.
Inserting `luaotfload.aux.fixup_fontdata' at position 1 in `luaotfload.patch_fon
t_unsafe'.
Inserting `luaotfload.aux.set_capheight' at position 3 in `luaotfload.patch_font
'.
Inserting `luaotfload.rewrite_fontname' at position 4 in `luaotfload.patch_font'
.
luaotfload | main : initialization completed in 0.124 seconds
Babel <3.15> and hyphenation patterns for 1 language(s) loaded.
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/report.cls
Document Class: report 2014/09/29 v1.4h Standard LaTeX document class
(/usr/local/texlive/2017/texmf-dist/tex/latex/base/size11.clo
File: size11.clo 2014/09/29 v1.4h Standard LaTeX file (size option)
luaotfload | db : Font names database loaded from /home/me/.texlive2017/texmf-va
r/luatex-cache/generic/names/luaotfload-names.luc(load luc: /home/me/.texlive201
7/texmf-var/luatex-cache/generic/fonts/otl/lmroman10-regular.luc))
\c@part=\count79
\c@chapter=\count80
\c@section=\count81
\c@subsection=\count82
\c@subsubsection=\count83
\c@paragraph=\count84
\c@subparagraph=\count85
\c@figure=\count86
\c@table=\count87
\abovecaptionskip=\skip41
\belowcaptionskip=\skip42
\bibindent=\dimen102
) (/usr/local/texlive/2017/texmf-dist/tex/latex/base/size12.clo
File: size12.clo 2014/09/29 v1.4h Standard LaTeX file (size option)

! You can't use `\spacefactor' in vertical mode.
\@->\spacefactor 
                 \@m {}
l.54 \normalsize

? x


Here is how much of LuaTeX's memory you used:
 233 strings out of 494483
 100000,89155 words of node,token memory allocated 322 words of node memory still in use:
   1 hlist, 1 rule, 1 dir, 2 attribute, 45 glue_spec, 2 attribute_list, 1 write 
nodes
   avail lists: 2:8,3:1,4:1,5:1,7:2,9:3
 4456 multiletter control sequences out of 65536+600000
 15 fonts using 723367 bytes
 22i,0n,19p,108b,40s stack positions out of 5000i,500n,10000p,90000000b,100000s

warning  (pdf backend): no pages of output.

PDF statistics: 0 PDF objects out of 1000 (max. 8388607)
 0 named destinations out of 1000 (max. 131072)
 1 words of extra memory for PDF output out of 10000 (max. 100000000)

答案1

這樣的事情會做嗎?

\documentclass[11pt]{report}

\ifdefined\HCode
  \let\small\undefined
  \let\footnotesize\undefined
  \let\scriptsize\undefined
  \let\tiny\undefined
  \let\large\undefined
  \let\Large\undefined
  \let\LARGE\undefined
  \let\huge\undefined
  \makeatletter
  \input{size12.clo}
  \makeatother
\fi

\begin{document}
my report here
\end{document}

答案2

在裡面KOMA 腳本類這可以透過命令輕鬆完成\KOMAoption,該命令允許在外部確定類別選項\documentclass,無論是在序言內部還是外部。 (如果在序言之外發布,fontsize選項聲明將從該點開始生效。)

\documentclass{scrartcl}
\KOMAoption{fontsize}{12pt}
\begin{document}
Some 12~pt-sized text (default is 11~pt).
\end{document}

答案3

與一個標準級你可以載入包scrextend。然後可以在加載此包時或稍後通過\KOMAoption或更改字體大小\KOMAoptions

\documentclass[11pt]{article}
\usepackage[fontsize=12pt]{scrextend}
\begin{document}
my report here
\par \bigskip
\KOMAoptions{fontsize=14pt}%
my report here
\end{document}

相關內容