我想添加\newkomavar
到我的.cls
文件中并在.lco
文件中使用它。
但似乎 .lco 在 .cls 之前被调用,因此不起作用。如何定义新的 koma 变量并在 .lco 文件中使用它们?
.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{businessletter}[2023-04-20 business letter]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrlttr2}}
\ProcessOptions\relax
\LoadClass{scrlttr2}
\newkomavar[IBAN]{fromiban}
\newkomavar[BIC]{frombic}
.lco
\ProvidesFile{DonaldDaisy.lco}[2023/04/20]%
\setkomavar{frombank}{Sparkasse Entenhausen}
\setkomavar{fromiban}{DE98~1605~0000~7512~0130~19}
\setkomavar{frombic}{WELADED2PMB}
.tex
\documentclass[fontsize=12pt,
DonaldDaisy,
]{businessletter}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{ebgaramond}
\usepackage{blindtext}
\begin{document}
\begin{letter}{Max Mustermann\\Musterstraße 1\\12345 Musterstadt}
\opening{Hello,}
\Blindtext
\closing{Mit freundlichen Grüßen}
\end{letter}
\end{document}
答案1
使用\documentclass
加载lco
-files已被弃用并会导致警告:
Class scrlttr2 Warning: loading of LCO via class option `DonaldDaisy'.
(scrlttr2) Note: Loading a LCO via class option is deprecated.
(scrlttr2) You should use `\LoadLetterOption{DonaldDaisy}'
(scrlttr2) instead.
因此你应该使用:
\begin{filecontents*}{businessletter.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{businessletter}[2023-04-20 business letter]
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrlttr2}}
\ProcessOptions\relax
\LoadClass{scrlttr2}
\newkomavar[IBAN]{fromiban}
\newkomavar[BIC]{frombic}
\end{filecontents*}
\begin{filecontents*}{DonaldDaisy.lco}
\ProvidesFile{DonaldDaisy.lco}[2023/04/20]%
\setkomavar{frombank}{Sparkasse Entenhausen}
\setkomavar{fromiban}{DE98~1605~0000~7512~0130~19}
\setkomavar{frombic}{WELADED2PMB}
\end{filecontents*}
\documentclass[fontsize=12pt,
]{businessletter}
%\usepackage[utf8]{inputenc}% not needed since LaTeX 2018/04/01
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{ebgaramond}
\usepackage{blindtext}
\LoadLetterOption{DonaldDaisy}
\begin{document}
\begin{letter}{Max Mustermann\\Musterstraße 1\\12345 Musterstadt}
\opening{Hello,}
\Blindtext
\closing{Mit freundlichen Grüßen}
\end{letter}
\end{document}
相反。我甚至建议不要在包装类中定义新变量,而是在 lco 文件或包装包中定义,这样它们也可以与包一起使用scrletter
,因此也可以与scrletter
作为包装类的scrartcl
类一起使用scrletter
:
\begin{filecontents*}{businessletter.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{businessletter}[2023-04-20 business letter]
\LoadClassWithOptions{scrletter}
\LoadLetterOption{businessletter}
\end{filecontents*}
\begin{filecontents*}{businessletter.lco}
\ProvidesFile{bussinessletter.lco}[2023-04-20 business letter]
\newkomavar[IBAN]{fromiban}
\newkomavar[BIC]{frombic}
\end{filecontents*}
\begin{filecontents*}{DonaldDaisy.lco}
\ProvidesFile{DonaldDaisy.lco}[2023/04/20]%
\Ifkomavar{fromiban}{}{\LoadLetterOption{bussinessletter.lco}}
\setkomavar{frombank}{Sparkasse Entenhausen}
\setkomavar{fromiban}{DE98~1605~0000~7512~0130~19}
\setkomavar{frombic}{WELADED2PMB}
\end{filecontents*}
\documentclass[fontsize=12pt]{businessletter}
%\usepackage[utf8]{inputenc}% not needed since LaTeX 2018/04/01
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{ebgaramond}
\usepackage{blindtext}
\LoadLetterOption{DonaldDaisy}
\begin{document}
\begin{letter}{Max Mustermann\\Musterstraße 1\\12345 Musterstadt}
\opening{Hello,}
\Blindtext
\closing{Mit freundlichen Grüßen}
\end{letter}
\end{document}