我真的很难让 if 语句正常工作....下面是包含所需所有代码的 zip 文件的链接:https://www.dropbox.com/s/ojsj33oe9ac4g09/latex-rechnung.zip?dl=0
我的代码:
\documentclass[a4paper]{scrlttr2}
\usepackage[top=2cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{color}
\usepackage[hidelinks]{hyperref}
\usepackage{lipsum}
\usepackage{xifthen}
\usepackage[german]{invoice}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\def\UnitDay{Preis/Tag}% <========================================
\newcommand{\FeeDay@Title}{% <==========================================
\\
\noindent\textbf{\Activity}&&\UnitDay&\Count&\Amount\ (\BC)\\
\hline%
}%
\newcommand{\FeeDay}[3]{% Yields state 3, Print Fee Item <==============
%
% #1 Contents
% #2 Fee per Day
% #3 Unit Count
%
\ifcase\Flag % 0: Invoice not started yet
\error@message{\MissingOpening}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 1: Start invoice
%
\error@message{\MissingProject}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 2: Start project, print title
%
\FeeDay@Title%
\Fee@Line{#1}{#2}{#3}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 3: Print remuneration item
%
\Fee@Line{#1}{#2}{#3}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 4: Print subtotal remuneration
%
\warning@message{\FeeSTExists}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 5: Expense item
%
\error@message{\FeeBeforeExpense}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 6: Print subtotal expenses
%
\error@message{\FeeBeforeExpense}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 7: Print subtotal project
%
\error@message{\ProjectCompletedNoFee}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 8: Print total, close invoice
%
\error@message{\InvoiceCompletedNoFee}%
%
%
\else \error@message{\InternalError}%
\fi%
}%
\makeatother
\renewcommand{\familydefault}{\sfdefault}
% include meta data
\include{_data} % <============== delete in this file the following data!
% ################## invoice DATA ##################
\newcommand{\invoiceDate}{\today} % Datum der rechnungsstellung
\newcommand{\invoiceReference}{2019\_02\_04\_1} % Rechnungsnummer (z.B. 20150122-4) YYYYMMDD-1
\newcommand{\invoiceSalutation}{} % die Anrede
\newcommand{\invoiceText}{Folgende Positionen werden in Rechnung gestellt:} % Rechnungstext
\newcommand{\invoiceEnclosures}{} % \encl{} einfügen
\newcommand{\invoiceClosing}{Mit freundlichen Grüßen}
% ################## invoice DATA ##################
% ##################Job DATA ####################
\def \performaceStart {14.01.2019}
\def \performaceEnd {01.02.2019}
% ##################Job DATA ####################
% ################## Customer DATA ##################
\newcommand{\customerCompany}{Firma ABC} %ggf. Firma
\newcommand{\customerName}{Mustermann} % Name
\newcommand{\customerStreet}{Straße 123} % Straße
\newcommand{\customerZIP}{12345} % Postleitzahl
\newcommand{\customerCity}{Musterstadt} % Ort
\newcommand{\customerNumber}{1000} % Kundennummer <==================
% ################## Customer DATA ##################
\setkomavar{fromname}{\senderName}
\setkomavar{fromaddress}{\senderStreet \\ \senderZIP \ \senderCity}
\setkomavar{place}{\senderCity}
\setkomavar{date}{\invoiceDate}
\setkomavar{fromphone}{\senderTelephone}
\setkomavar{frommobilephone}{\senderMobilephone}
\setkomavar{fromemail}{\href{mailto:\senderEmail}{\nolinkurl{\senderEmail}}}
\setkomavar{subject}{Rechnung}
\def \invoicenr{Rechnungsnummer: }% <========================================
\def \customernr{Kundennummer: }%
\def \performanceDuration{Leistungszeitraum: }
\setkomavar{location}{\vspace*{-1.99cm}
\\[\baselineskip] \\[\baselineskip]
\flushright\small \invoicenr \invoiceReference\\[5pt]
\customernr\\
\customerNumber\\[5pt]
\performanceDuration\\
\newcommand{\downow}{
\if \performanceEnd == {}
\performaceStart{} -- \performaceEnd
\else
\performanceStart
}
% \performaceStart{} -- \performaceEnd
}
\setkomavar{firsthead}{\hfill
\parbox[t][\headheight][t]{7.3cm}
{%
\footnotesize
\raggedright
\flushright
\color[gray]{.3}%
}%
}
\begin{document}
\begin{letter}{\customerCompany \\ \customerName \\
\customerStreet \\ \customerZIP \ \customerCity}\vspace*{-3.5cm}
\opening{\invoiceSalutation}
\invoiceText
\begin{invoice}{Euro}{0}
\ProjectTitle{Tagesleistungen} %
\FeeDay{Freelancing} {300} {1}
%\ProjectTitle{Projekttitel} %
%\Fee{Überstunden} {37.5} {4}
% Auslagen
%\EBC{Softwarenutzung} {150.00}
%\EBCi{Hotel, 12 Nächte} {2400.00}
%\STExpenses
% Rabatt
\Discount{Rabatt} {0} %
\end{invoice}
\ps Bitte zahlen Sie den Gesamtbetrag unter Angabe der Rechnungsnummer auf das aufgeführte Konto.
\ps Kleinunternehmerregelung:\\
Im ausgewiesenen Betrag ist gemäß § 19 UStG keine Umsatzsteuer
enthalten.
\closing{\invoiceClosing}
\invoiceEnclosures
\vspace*{3.9cm}
\footnotesize \ps \textbf{Bankverbindung:}\hspace{6mm}\accountBankName, \accountIBAN, \accountBIC
\footnotesize \ps \textbf{Steuernummer:}\hspace{8mm}\taxID
\end{letter}
\end{document}
我想要一个 if 语句来检查是否\performaceEnd
未定义或为空。如果为空,则\performanceDuration
只会显示\performanceStart
,如果\performanceEnd
已定义,则显示\performanceStart{} -- \performanceEnd
我怎麼做呢?
答案1
编写测试的正确方法是
\ifx\performanceEnd\undefined
\performanceStart
\else\ifx\performanceEnd\empty
\performanceStart
\else
\performanceStart{} -- \performanceEnd
\fi\fi
\ifperformanceEnd
您还可以通过以下方式声明布尔值
\newif\ifperformanceEnd
在序言中的任何地方\performanceEnd
检查
\performanceEndfalse
\ifx\performanceEnd\undefined\else
\ifx\performanceEnd\empty\else
\performanceEndtrue
\fi\fi
那么你可以写
\ifperformanceEnd
\performanceStart{} -- \performanceEnd
\else
\performanceStart
\fi
甚至
\performanceStart\ifperformanceEnd{} -- \performanceEnd\fi
答案2
好的,我们开始吧:正如@eric-domenjoud 指出的那样,您可以使用它\ifx
来构建所需的文本变体。顺便说一句,考虑添加一个“seit”以明确表示表演时间尚未结束。
我在下面的代码中将错误写的变量更正\performaceStart
为\performaceEnd
正确的变量,\performanceStart
并\performanceEnd
在下面完整的代码中将其更正。
正如我们在您上一个问题中所做的那样,我们必须再次更改命令代码,\location
如下所示:
\setkomavar{location}{%
\\[\baselineskip] \\[\baselineskip]
\flushright\small \invoicenr \invoiceReference\\[5pt]
\customernr\\
\customerNumber\\[5pt]
\performanceDuration\\
\ifx\performanceEnd\undefined % <=======================================
\performanceStart
\else\ifx\performanceEnd\empty
\performanceStart
\else
\performanceStart{} -- \performanceEnd
\fi\fi % <==============================================================
}
然后我们得到以下代码(您需要使用问题链接的 zip 文件中的所有文件才能编译它!)
\documentclass[a4paper]{scrlttr2}
\usepackage[top=2cm, bottom=1cm, left=2cm, right=2cm]{geometry}
\usepackage{graphicx}
\usepackage{lmodern}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{color}
\usepackage[hidelinks]{hyperref}
%\usepackage {ifthen}
\usepackage[german]{invoice}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makeatletter
\def\UnitDay{Preis/Tag}% <========================================
\newcommand{\FeeDay@Title}{% <==========================================
\\
\noindent\textbf{\Activity}&&\UnitDay&\Count&\Amount\ (\BC)\\
\hline%
}%
\newcommand{\FeeDay}[3]{% Yields state 3, Print Fee Item <==============
%
% #1 Contents
% #2 Fee per Day
% #3 Unit Count
%
\ifcase\Flag % 0: Invoice not started yet
\error@message{\MissingOpening}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 1: Start invoice
%
\error@message{\MissingProject}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 2: Start project, print title
%
\FeeDay@Title%
\Fee@Line{#1}{#2}{#3}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 3: Print remuneration item
%
\Fee@Line{#1}{#2}{#3}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 4: Print subtotal remuneration
%
\warning@message{\FeeSTExists}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 5: Expense item
%
\error@message{\FeeBeforeExpense}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 6: Print subtotal expenses
%
\error@message{\FeeBeforeExpense}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 7: Print subtotal project
%
\error@message{\ProjectCompletedNoFee}%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\or % 8: Print total, close invoice
%
\error@message{\InvoiceCompletedNoFee}%
%
%
\else \error@message{\InternalError}%
\fi%
}%
\makeatother
\renewcommand{\familydefault}{\sfdefault}
% include meta data
\include{_data} % <============== delete in this file the following data!
% ################## invoice DATA ##################
\newcommand{\invoiceDate}{\today} % Datum der rechnungsstellung
\newcommand{\invoiceReference}{2019\_01\_01\_1} % Rechnungsnummer (z.B. 20150122-4) YYYYMMDD-1
\newcommand{\invoiceSalutation}{Sehr geehrte Damen und Herren,} % die Anrede
\newcommand{\invoiceText}{Folgende Positionen werden in Rechnung gestellt:} % Rechnungstext
\newcommand{\invoiceEnclosures}{} % \encl{} einfügen
\newcommand{\invoiceClosing}{Mit freundlichen Grüßen}
% ################## invoice DATA ##################
% ##################Job DATA ####################
\def \performanceStart {01.01.2019}
%\def \performanceEnd {02.01.2019}
% ##################Job DATA ####################
% ################## Customer DATA ##################
\newcommand{\customerCompany}{Firma ABC} %ggf. Firma
\newcommand{\customerName}{Max Mustermann} % Name
\newcommand{\customerStreet}{Musterstraße 10} % Straße
\newcommand{\customerZIP}{12345} % Postleitzahl
\newcommand{\customerCity}{Musterort} % Ort
\newcommand{\customerNumber}{1000} % Kundennummer <==================
% ################## Customer DATA ##################
\setkomavar{fromname}{\senderName}
\setkomavar{fromaddress}{\senderStreet \\ \senderZIP \ \senderCity}
\setkomavar{place}{\senderCity}
\setkomavar{date}{\invoiceDate}
\setkomavar{fromphone}{\senderTelephone}
\setkomavar{frommobilephone}{\senderMobilephone}
\setkomavar{fromemail}{\href{mailto:\senderEmail}{\nolinkurl{\senderEmail}}}
\setkomavar{subject}{Rechnung}
\def \invoicenr{Rechnungsnummer: }% <========================================
\def \customernr{Kundennummer: }%
\def \performanceDuration{Leistungszeitraum: }
\setkomavar{location}{%
\\[\baselineskip] \\[\baselineskip]
\flushright\small \invoicenr \invoiceReference\\[5pt]
\customernr\\
\customerNumber\\[5pt]
\performanceDuration\\
\ifx\performanceEnd\undefined % <=======================================
\performanceStart
\else\ifx\performanceEnd\empty
\performanceStart
\else
\performanceStart{} -- \performanceEnd
\fi\fi % <==============================================================
}
\setkomavar{firsthead}{\hfill
\parbox[t][\headheight][t]{7.3cm}{%
\footnotesize
\raggedright
\flushright
\color[gray]{.3}%
\begin{tabular}{rl}
Anschrift & \usekomavar{fromname}\\
& \senderStreet\\
& \senderZIP \ \senderCity \\
\\
%\Telefon \ Telefon: \` \senderTelephone \\
Mobil & \usekomavar{frommobilephone} \\
E-Mail & \usekomavar{fromemail} \\
%Webseite & {\normalfont\ttfamily \senderWeb } \\
\\
Steuernummer & \taxID \\
\\
Institut & \accountBankName \\
IBAN & \accountIBAN \\
BIC & \accountBIC
\end{tabular}
}%
}
\begin{document}
\begin{letter}{\customerCompany \\ \customerName \\
\customerStreet \\ \customerZIP \ \customerCity}
\opening{\invoiceSalutation}
\invoiceText
\begin{invoice}{Euro}{0}
\ProjectTitle{Tagesleistungen} %
\FeeDay{Freelance Arbeit} {10} {1}
\ProjectTitle{Projekttitel} %
\Fee{Überstunden} {20} {1}
% Auslagen
%\EBC{Hotel, 12 Nächte} {2400.00} % \EBCi{Hotel, 12 Nächte} {2400.00}
%\STExpenses
% Rabatt
\Discount{Rabatt} {0} %
\end{invoice}
\ps Bitte zahlen Sie den Gesamtbetrag unter Angabe der Rechnungsnummer auf das aufgeführte Konto.
\ps Kleinunternehmerregelung:\\
Im ausgewiesenen Betrag ist gemäß § 19 UStG keine Umsatzsteuer
enthalten.
\closing{\invoiceClosing}
\invoiceEnclosures
\end{letter}
\end{document}
结果如下(请参阅我注释的定义\performanceEnd
):
如果你想添加“seit”,正如这个答案开头所说,你可以使用
\setkomavar{location}{%
\\[\baselineskip] \\[\baselineskip]
\flushright\small \invoicenr \invoiceReference\\[5pt]
\customernr\\
\customerNumber\\[5pt]
\performanceDuration\\
\ifx\performanceEnd\undefined % <=======================================
seit \performanceStart
\else\ifx\performanceEnd\empty
seit \performanceStart
\else
\performanceStart{} -- \performanceEnd
\fi\fi % <==============================================================
}
结果如下: