我想接受用户输入(有时这将是大段落)并生成一个 LaTeX 文档。我正在考虑使用几个简单的正则表达式来替换\with\textbackslash的所有实例以及{or的所有实例}与\}or \{。
我怀疑这是否足够。我还需要做什么?注意:如果有为此制作的特殊库,我正在使用 python。
为了澄清,我不希望任何东西被解析为 LaTeX 语法:$a$应该替换为\$a\$.
我想接受用户输入(有时这将是大段落)并生成一个 LaTeX 文档。我正在考虑使用几个简单的正则表达式来替换\with\textbackslash的所有实例以及{or的所有实例}与\}or \{。
我怀疑这是否足够。我还需要做什么?注意:如果有为此制作的特殊库,我正在使用 python。
为了澄清,我不希望任何东西被解析为 LaTeX 语法:$a$应该替换为\$a\$.
If your input is plain text and you are in a normal catcode regime, you must do the following substitutions:
\ → \textbackslash{} (note the empty group!){ → \{} → \}$ → \$& → \&# → \#^ → \textasciicircum{} (requires the textcomp package)_ → \_~ → \textasciitilde{}% → \%In addition, the following substitutions are useful at least when using the OT1 encoding (and harmless in any case):
< → \textless{}> → \textgreater{}| → \textbar{}And these three disable the curly quotes:
" → \textquotedbl{}' → \textquotesingle{}` → \textasciigrave{}