跳至内容

生成的 LaTeX A4 信函示例

使用 LaTeX 模式的 jinja2 生成一封信。

此处的简历示例来自 http://www.LaTeXTemplates.com。

与传统的 jinja2 不同,latexmode jinja2 使用不同的语法来避免冲突。

  • 行语句为:%%(例如 %% if x = y
  • 变量开头为:\VAR{ ... }
  • 注释为:\#{ ... }
  • 块为:\BLOCK{ ... }
  • 行注释前缀为:%#(例如 %# commented out line)。

letter.org

* from details
** name

John Doe

** address

1234 NW Bobcat Lane,
Bobcat City,
MO
65584-5678.

** telephone

+1-541-754-3010

** email

[email protected]

** signature image


* body

Could I get world peace? Failing that maybe an Xbox.

Many thanks!

* to address

123 Elf Road,
North Pole,
88888

* postscript

P.S. An iPhone would also be acceptable.

letter.jinja2

% Thin Formal Letter
% LaTeX Template
% Version 2.0 (7/2/17)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% Author:
% Vel ([email protected])
%
% Originally based on an example on WikiBooks 
% (https://wikibooks.cn/wiki/LaTeX/Letters) but rewritten as of v2.0
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%

%----------------------------------------------------------------------------------------
%   DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------

\documentclass[10pt]{letter} % 10pt font size default, 11pt and 12pt are also possible

\usepackage{geometry} % Required for adjusting page dimensions

\usepackage{graphicx}

%\longindentation=0pt % Un-commenting this line will push the closing "Sincerely," to the left of the page

\geometry{
    paper=a4paper, % Change to letterpaper for US letter
    top=3cm, % Top margin
    bottom=1.5cm, % Bottom margin
    left=4.5cm, % Left margin
    right=4.5cm, % Right margin
    %showframe, % Uncomment to show how the type block is set on the page
}

\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage[utf8]{inputenc} % Required for inputting international characters

\usepackage{stix} % Use the Stix font by default

\usepackage{microtype} % Improve justification

%----------------------------------------------------------------------------------------
%   YOUR NAME & ADDRESS SECTION
%----------------------------------------------------------------------------------------
%
%% set fromdetails = root.at("from details")

\signature{
    \VAR{fromdetails.at("name").body}
} % Your name for the signature at the bottom

\address{
\VAR{ fromdetails.at("address").body.text.replace("\n", "\\\\ \n") } \\
\VAR{ fromdetails.at("telephone").body } \\
\VAR{ fromdetails.at("email").body }
} % Your address and phone number

%----------------------------------------------------------------------------------------

\begin{document}

%----------------------------------------------------------------------------------------
%   ADDRESSEE SECTION
%----------------------------------------------------------------------------------------

\begin{letter}{
\VAR{ root.at("to address").body.text.replace("\n", "\\\\ \n") }
} % Name/title of the addressee

%----------------------------------------------------------------------------------------
%   LETTER CONTENT SECTION
%----------------------------------------------------------------------------------------

\opening{\textbf{Dear Sir or Madam,}}


\VAR{ root.at("body").body.latexed }


\vspace{2\parskip} % Extra whitespace for aesthetics

\closing{
Yours faithfully,
}

\ps{
%% if root.has("postscript")
\VAR{ root.at("postscript").body.latexed }
%% endif
} % Postscript text, comment this line to remove it

% \encl{Copyright permission form} % Enclosures with the letter, comment this line to remove it

%----------------------------------------------------------------------------------------

\end{letter}

\end{document}

正在运行

orji out --latexmode letter.org letter.jinja2

将输出

% Thin Formal Letter
% LaTeX Template
% Version 2.0 (7/2/17)
%
% This template has been downloaded from:
% http://www.LaTeXTemplates.com
%
% Author:
% Vel ([email protected])
%
% Originally based on an example on WikiBooks 
% (https://wikibooks.cn/wiki/LaTeX/Letters) but rewritten as of v2.0
%
% License:
% CC BY-NC-SA 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
%

%----------------------------------------------------------------------------------------
%   DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------

\documentclass[10pt]{letter} % 10pt font size default, 11pt and 12pt are also possible

\usepackage{geometry} % Required for adjusting page dimensions

\usepackage{graphicx}

%\longindentation=0pt % Un-commenting this line will push the closing "Sincerely," to the left of the page

\geometry{
    paper=a4paper, % Change to letterpaper for US letter
    top=3cm, % Top margin
    bottom=1.5cm, % Bottom margin
    left=4.5cm, % Left margin
    right=4.5cm, % Right margin
    %showframe, % Uncomment to show how the type block is set on the page
}

\usepackage[T1]{fontenc} % Output font encoding for international characters
\usepackage[utf8]{inputenc} % Required for inputting international characters

\usepackage{stix} % Use the Stix font by default

\usepackage{microtype} % Improve justification

%----------------------------------------------------------------------------------------
%   YOUR NAME & ADDRESS SECTION
%----------------------------------------------------------------------------------------
%
\signature{
    John Doe
} % Your name for the signature at the bottom

\address{
1234 NW Bobcat Lane,\\ 
Bobcat City,\\ 
MO\\ 
65584-5678. \\
+1-541-754-3010 \\
[email protected]
} % Your address and phone number

%----------------------------------------------------------------------------------------

\begin{document}

%----------------------------------------------------------------------------------------
%   ADDRESSEE SECTION
%----------------------------------------------------------------------------------------

\begin{letter}{
123 Elf Road,\\ 
North Pole,\\ 
88888
} % Name/title of the addressee

%----------------------------------------------------------------------------------------
%   LETTER CONTENT SECTION
%----------------------------------------------------------------------------------------

\opening{\textbf{Dear Sir or Madam,}}


Could I get world peace? Failing that maybe an Xbox.

Many thanks!


\vspace{2\parskip} % Extra whitespace for aesthetics

\closing{
Yours faithfully,
}

\ps{
P.S. An iPhone would also be acceptable.
} % Postscript text, comment this line to remove it

% \encl{Copyright permission form} % Enclosures with the letter, comment this line to remove it

%----------------------------------------------------------------------------------------

\end{letter}

\end{document}