文章摘要
本文详细介绍了将常见小说txt文件导入Latex进行编译处理的方法。首先,通过正则表达式去除空白换行,并使用特定表达式替换章节标题以符合Latex格式。接着,将换行符转换为Latex的换行符,并对特殊字符进行批量替换。文章还展示了如何整合字体设置和命令,包括定义中文字体和字体样式,以及如何设置文件头和文件尾。最后,提供了编译命令,使用latexmk工具进行编译,并设置了相关选项以确保编译过程顺利进行。
该示例适用于常见小说txt导入到Latex进行编译处理的方法。
去除空白换行
使用如下正则表达式:
^\s*\r?\n
替换内容留空,点击全部替换
替换章节
使用如下正则表达式(注意最后有一个空格):
第\d+章
替换内容:
\chapter{
补全最后的花括号,使用如下正则表达式:
\\chapter\{(.*)$
替换内容:
\chapter{$1}
替换换行符
Latex中换行符为\par,使用如下正则表达式:
\n
替换内容:
\\par \n
特殊字符处理
同样批量替换即可
%:\%
$:\$
&:\&
_:\_
#:\#
{:\{
}:\}
整合进入文件
文件头:
latex
\documentclass[lang=cn, 8pt ,scheme=chinese, mode=fancy, AutoFakeBold=true,device=pad,nofont]{elegantbook}
\usepackage{graphicx}
\usepackage{textcomp}
\usepackage{tablefootnote}
\usepackage[dvipsnames]{xcolor}
\usepackage{indentfirst}
\setCJKmainfont[BoldFont={Noto Serif CJK SC Black},AutoFakeSlant]{Noto Serif CJK SC}
\setCJKsansfont[BoldFont={Noto Sans CJK SC Black},AutoFakeSlant]{Noto Sans CJK SC}
\setCJKmonofont[AutoFakeBold,AutoFakeSlant]{FandolFang}
\setCJKfamilyfont{zhsong}{Noto Serif CJK SC}
\setCJKfamilyfont{zhhei}{Noto Sans CJK SC}
\setCJKfamilyfont{zhkai}[AutoFakeBold,AutoFakeSlant]{FandolKai}
\setCJKfamilyfont{zhfs}[AutoFakeBold,AutoFakeSlant]{FandolFang}
\newcommand*{\songti}{\CJKfamily{zhsong}}
\newcommand*{\heiti}{\CJKfamily{zhhei}}
\newcommand*{\kaishu}{\CJKfamily{zhkai}}
\newcommand*{\fangsong}{\CJKfamily{zhfs}}
\renewcommand{\thepart}{第\zhnumber{\arabic{part}}卷}
\begin{document}
\tableofcontents
\setlength{\parindent}{0em}
\chapter*{简介}
文件尾:
latex
\end{document}
编译命令
bash
latexmk -pdf -file-line-error -interaction=nonstopmode -synctex=1 -xelatex main.tex
本文是原创文章,采用 CC BY-NC-SA 4.0 协议,完整转载请注明来自 烧鸡
评论
隐私政策
0/500
滚动到此处加载评论...


