处理文本部分时保留空格的良好做法是什么?
我读到空格字符在标记列表中被抑制。我也尝试使用字符串。
\documentclass[a6paper,french]{article}
\usepackage{luatex85}
\usepackage[margin=1.5cm]{geometry}
\usepackage{fourier}
\usepackage{fontspec}
\setmainfont{Erewhon}[
Extension=.otf,
UprightFont=*-Regular,
ItalicFont=*-Italic,
BoldFont=*-Bold,
BoldItalicFont=*-BoldItalic,
SlantedFont=*-RegularSlanted,
BoldSlantedFont=*-BoldSlanted,
]
\setsansfont{texgyreheros}[
Scale=MatchUppercase,% or MatchLowercase
Extension=.otf,
UprightFont=*-regular,
ItalicFont=*-italic,
BoldFont=*-bold,
BoldItalicFont=*-bolditalic,
]
\usepackage{babel}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\Pythagore}{m}{%
\tl_new:N \l_text_tl
\str_new:N \l_text_str
\tl_set:Nn \l_text_tl {Dans\ le\ triangle\ ...\ rectangle\ en\ #1,\ on\ utlise\ le\ theorème\ de\ Pythagore:}
\str_set:Nn \l_text_str {Dans\ le\ triangle\ ...\ rectangle\ en\ #1,\ on\ utlise\ le\ theorème\ de\ Pythagore:}
\l_text_tl
% how to have a new line
\l_text_str
}
\ExplSyntaxOff
\begin{document}
\Pythagore{A B}
Dans le triangle ... rectangle en A B, on utlise le theorème de Pythagore:
\end{document}
答案1
\ExplSyntaxOn
和之间的\ExplSyntaxOff
catcode~
被改为空格。因此,~
可以在代码块中用作空格expl3
。此外\tl_new:N
,和\str_new:N
只能被调用一次,因此它们不属于命令。
\documentclass[a6paper,french]{article}
\usepackage{luatex85}
\usepackage[margin=1.5cm]{geometry}
\usepackage{fourier}
\usepackage{fontspec}
\setmainfont{Erewhon}[
Extension=.otf,
UprightFont=*-Regular,
ItalicFont=*-Italic,
BoldFont=*-Bold,
BoldItalicFont=*-BoldItalic,
SlantedFont=*-RegularSlanted,
BoldSlantedFont=*-BoldSlanted,
]
\setsansfont{texgyreheros}[
Scale=MatchUppercase,% or MatchLowercase
Extension=.otf,
UprightFont=*-regular,
ItalicFont=*-italic,
BoldFont=*-bold,
BoldItalicFont=*-bolditalic,
]
\usepackage{babel}
\usepackage{xparse}
\ExplSyntaxOn
\tl_new:N \l_text_tl
\str_new:N \l_text_str
\NewDocumentCommand{\Pythagore}{m}{%
\tl_set:Nn \l_text_tl {Dans~le~triangle~...~rectangle~en~#1,~on~utlise~~le~theorème~de~Pythagore:}
\str_set:Nn \l_text_str {Dans~le~triangle~...~rectangle~en~#1,~on~utlise~le~theorème~de~Pythagore:}
\l_text_tl
% how to have a new line
\l_text_str
}
\ExplSyntaxOff
\begin{document}
\Pythagore{A B}
Dans le triangle ... rectangle en A B, on utlise le theorème de Pythagore:
\end{document}