
이메일 헤더에 이메일 주소 형식을 지정하기 위해 다음 매크로를 준비했습니다.
\usepackage{xifthen}% Provides \ifthenelse and \isempty
% E-Mail header strings with format.
\newcommand{\fromString}{\textbf{From:} }
\newcommand{\toString}{\textbf{To:} }
% E-Mail with or without alias.
\newcommand{\email}[2][]{%
\ifthenelse{\isempty{#1}}%
{<#2>}% E-Mail only
{"#1" <#2>}% Alias and E-Mail
}
% E-Mail header From:
\newcommand{\emailFrom}[2][]{%
\ifthenelse{\isempty{#1}}%
{\fromString \email{#2}\\}% E-Mail only
{\fromString \email[#1]{#2}\\}% Alias and E-Mail
}
% E-Mail header To:
\newcommand{\emailTo}[2][]{%
\ifthenelse{\isempty{#1}}%
{\toString \email{#2}\\}% E-Mail only
{\toString \email[#1]{#2}\\}% Alias and E-Mail
}
매크로는 다음 예에서 설명한 대로 사용할 수 있습니다. []
대신 선택적 인수로 사용된다는 점에 유의하세요 {}
.
\email[Doe, John]{[email protected]}
\emailFrom[Doe, John]{[email protected]}
\emailFrom{[email protected]}
\emailTo[Doe, John]{[email protected]}
\emailTo{[email protected]}
형식화된 출력은 다음과 같습니다.
"도우, 존" <[이메일 보호됨]>
에서:"도우, 존" <[이메일 보호됨]>
에서:<[이메일 보호됨]>
에게:"도우, 존" <[이메일 보호됨]>
에게:<[이메일 보호됨]>
여러 전자 메일 주소에 사용할 수 있도록 매크로를 확장하려면 어떻게 해야 합니까? 다음 예에서는 문제를 설명해야 합니다. 세 번째 예에서 볼 수 있듯이 별칭의 발생은 각 전자 메일 항목마다 개별적으로 나타납니다.
에게:"도우, 존" <[이메일 보호됨]>, "도우, 제인" <[이메일 보호됨]>
에게:<[이메일 보호됨]>, <[이메일 보호됨]>
에게:<[이메일 보호됨]>, "도우, 제인" <[이메일 보호됨]>
저는 라텍스에서 매크로를 처음 사용하기 때문에 제 명령을 전반적으로 개선하거나 이에 대한 의견을 남겨주셔도 좋습니다.
업데이트:
여러 이메일을 작업하면서 나는 이런 일이 일어날 수도 있다는 것을 깨달았습니다.아니요이메일 주소주어진, 오직이메일 별칭. 이는 회사 내부 대화 등 누군가가 이메일을 전달할 때 발생합니다. 그럼에도 불구하고 나는 이 형식을 유효한 이메일 헤더로 받아들입니다. 이 스키마를 매크로에 포함할 기회가 있습니까? 여기에 예가 있습니다.
From: John Doe
Subject: Re: E-Mail headers
Date: Wed, 22 Aug 2012 23:42:00 +0200
To: Jane Doe
답변1
주소가 하나이고 주소가 여러 개인 경우에는 다른 구문을 사용합니다.
\documentclass{article}
\usepackage[T1]{fontenc}
\makeatletter
\newif\if@emailenv
\newenvironment{emails}[1][\ignorespaces]
{\set@email@separator{#1}\@emailenvtrue\begin{flushleft}}
{\end{flushleft}}
\def\set@email@separator#1{%
\def\email@separator{#1\def\email@separator{,}}}
\newcommand{\@email}[2][]{%
\if@emailenv\else\begin{flushleft}\fi
\email@separator\space
\if\relax\detokenize{#1}\relax\else"#1" \fi
\texttt{<#2>}%
\if@emailenv\ignorespaces\else\end{flushleft}\fi
}
\newcommand{\email}{%
\if@emailenv\else\set@email@separator{\ignorespaces}\fi\@email}
\newcommand{\emailTo}{%
\if@emailenv\else\set@email@separator{\textbf{To:}}\fi\@email}
\newcommand{\emailFrom}{%
\if@emailenv\else\set@email@separator{\textbf{From:}}\fi\@email}
\newcommand{\emailsFrom}{\emails[\textbf{From:}]}
\newcommand{\emailsTo}{\emails[\textbf{To:}]}
\let\endemailsFrom\endemails
\let\endemailsTo\endemails
\makeatother
\begin{document}
\email{[email protected]}
\email[Doe, John]{[email protected]}
\emailTo{[email protected]}
\emailTo[Doe, John]{[email protected]}
\emailFrom{[email protected]}
\emailFrom[Doe, John]{[email protected]}
\begin{emails}
\email{[email protected]}
\email[Doe, John]{[email protected]}
\email[Doe, Jane]{[email protected]}
\end{emails}
\begin{emailsTo}
\email{[email protected]}
\email[Doe, John]{[email protected]}
\email[Doe, Jane]{[email protected]}
\end{emailsTo}
\begin{emailsFrom}
\email{[email protected]}
\email[Doe, John]{[email protected]}
\email[Doe, Jane]{[email protected]}
\end{emailsFrom}
\end{document}
답변2
이 솔루션 foreach
은TikZ / PGF. 이름과 메일을 양식 목록으로 지정합니다 name/mail,name/mail
.
코드
\documentclass[parskip]{scrartcl}
\usepackage[margin=15mm]{geometry}
\usepackage{tikz}
\usepackage{xifthen}
\newcommand{\toString}{\textbf{To:} }
\newcommand{\emailto}[1]% list ; "/" separates mail and name, "," separates people
{ \xdef\maillist{}% empty maillist
\foreach \x/\y [count=\c] in {#1}% for each iteration over the name/mail list, increase \c by one
{ \ifthenelse{\c=1}% if first iteration...
{\xdef\addcomma{}}% leave out comma
{\xdef\addcomma{,}}% else put one
\ifthenelse{\equal{\x}{}}% if no name given
{\xdef\maillist{\maillist\addcomma$<$\y$>$}}% put just <mail>
{\xdef\maillist{\maillist\addcomma"\x"$<$\y$>$}}% else put "name"<mail>
}
\toString\maillist% output of the final list
}
\begin{document}
\emailto{John Doe/[email protected],Jane Dane/[email protected],/[email protected]}
\end{document}
결과
편집 1:약간의 일반화: 이제 \email
다른 정의에 재사용할 수 있습니다. 선택적 매개변수를 사용하여 이 작업을 수행하는 방법을 모르겠습니다. 해당 숫자가 매개변수와 동일하지 않기 때문입니다.
코드
\newcommand{\email}[1]% list ; "/" separates mail and name, "," separates people
{ \xdef\maillist{}% empty maillist
\foreach \x/\y [count=\c] in {#1}% for each iteration over the name/mail list, increase \c by one
{ \ifthenelse{\c=1}% if first iteration...
{\xdef\addcomma{}}% leave out comma
{\xdef\addcomma{,}}% else put one
\ifthenelse{\equal{\x}{}}% if no name given
{\xdef\maillist{\maillist\addcomma$<$\y$>$}}% put just <mail>
{\xdef\maillist{\maillist\addcomma"\x"$<$\y$>$}}% else put "name"<mail>
}
}
\newcommand{\emailto}[1]
{ \email{#1}
\textbf{To: }\maillist
}
\newcommand{\emailfrom}[1]
{ \email{#1}
\textbf{From: }\maillist
}
결과
\emailto{John Doe/[email protected],Jane Dane/[email protected],/[email protected]}
\emailfrom{John Doe/[email protected],Jane Dane/[email protected],/[email protected]}
편집 2: 이제 완전히 다른 것을 경험해보세요:
이 솔루션은 을 사용하며 xstring
목록 형식은 입니다 (name)email;
.
여러분도 참고하세요세미콜론으로 목록을 종료해야 합니다.
코드
\documentclass[parskip]{scrartcl}
\usepackage[margin=10mm]{geometry}
\usepackage{xifthen}
\usepackage{xstring}
\usepackage{xcolor}
\newcommand{\email}[1]% (<name>)<email>;(<name>)<email>
{ \xdef\mylist{#1} % set mylist to the input
\xdef\myentry{} % empty myentry
\xdef\myname{} % empty myname
\xdef\myemail{} % empty myemail
\xdef\myoutput{} % empty myoutput
\xdef\mynumber{} % empty mynumber
\StrBefore{\mylist}{;}[\myentry] % get everything in mylist before ; and save it to myentry, so this should be the first person, e.g (name)mail
\StrLen{\myentry}[\mynumber] % save length of myentry to mynumber
\whiledo{\mynumber>0} % while myentry is not empty (e.g. length > 0)
{ \StrBetween{\myentry}{(}{)}[\myname] % extract what is between ( and ) in myentry and save it to myname
\StrPosition{\myentry}{)}[\mynumber] % save position of ) to mynumber
\ifthenelse{\mynumber>0} % if the character ) is found in myentry
{ \StrBehind{\myentry}{)}[\myemail]} % then get everything behind ), e.g the email
{ \xdef\myemail{\myentry}}% otherwise (e.g. no name present) set myemail to myentry
\StrLen{\myname}[\mynumber] % set mynumber to the length of mynem
\ifthenelse{\mynumber>0} % if length of myname is non-zero (e.g one was provided)
{ \xdef\myoutput{\myoutput"\myname"$<$\myemail$>$}} % then print "name"<mail>
{ \xdef\myoutput{\myoutput$<$\myemail$>$}} % else print <mail>
\StrBehind{\mylist}{;}[\mylist] % delete everything up to the first ; e.g the entry that was just worked with
\StrBefore{\mylist}{;}[\myentry] % new myentry is everything before the next ;
\StrLen{\myentry}[\mynumber] % determine length of myentry and save that number to mynumber
\ifthenelse{\mynumber>0} % if a new myentry is present (e.g not end of list)
{ \xdef\myoutput{\myoutput,}} % then add a comma
{} % else do nothing
}
%\myoutput % after all entrys were processed, output the result
}
\newcommand{\eMailTo}[1]%
{ \email{#1}
\textbf{To: }\myoutput
}
\newcommand{\eMailFromColor}[2][green!50!gray]%
{ \email{#2}
\textcolor{#1}{\textbf{From: }\myoutput}
}
\begin{document}
\eMailTo{(Doe, John)[email protected];(Dane, J. A. N. E)[email protected];[email protected];}
\eMailFromColor{(Doe, John)[email protected];(Dane, J. A. N. E)[email protected];[email protected];}
\eMailFromColor[red!80!black]{(Doe, John)[email protected];(Dane, J. A. N. E)[email protected];[email protected];}
\end{document}