如何将文档序言中的字体大小从 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}

相关内容