测试 KOMAvar 是否为空

测试 KOMAvar 是否为空

如何检测 KOMAvar 是否为空?

我想隐藏邮件图标来自电子邮件是空的。

\documentclass[refline=nodate]{scrlttr2}

\usepackage{lipsum,marvosym}

\setkomavar{fromname}{David} 
\setkomavar{fromemail}{}
\setkomavar{place}{here}
\setkomavar{backaddress}{}

\usekomavar[\edef\komaemail]{fromemail} % Defining a variabel komaemail

\makeatletter
    \setkomavar{fromaddress}{Road 17\\9900 place \hfill \usekomavar{place},~\usekomavar{date}\\[.3em]
        \ifx \@komaemail \@empty\relax\else % Testing for komaemail
            \hspace*{-1.3em}\Letter ~ \usekomavar{fromemail}
        \fi
    }
\makeatother


\begin{document}
\begin{letter}{%
    Name \\
    Adress \\
    Some place
}


\opening{No, just a regular mistake. Kif might! Why would a robot need to drink?}

\lipsum[2]

\closing{Out.}

\end{letter}
\end{document}

在此处输入图片描述

答案1

只需使用

 \Ifkomavarempty{fromemail}{true-code}{false-code}

例如。

示例输出

\documentclass[refline=nodate]{scrlttr2}

\usepackage{lipsum,marvosym}

\setkomavar{fromname}{David} 
\setkomavar{fromemail}{}
\setkomavar{place}{Here}
\setkomavar{backaddress}{}

\usekomavar[\edef\komaemail]{fromemail}

\setkomavar{fromaddress}{Road 17\\9900 Place \hfill
   \usekomavar{place},~\usekomavar{date}\\[.3em]
    \Ifkomavarempty{fromemail}{}{\usekomavar{fromemail}}%
    \Ifkomavarempty{place}{}{Hello, place is not empty!}%xo
    }

\begin{document}
\begin{letter}{%
    Name \\
    Adress \\
    Some place
}


\opening{No, just a regular mistake. Kif might! Why would a robot need
to drink?} 

\lipsum[2]

\closing{Out.}

\end{letter}
\end{document}

\edef没有设置 koma var。

相关内容