Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
繁星间漫步
冷杉
提交
d8e5f740
冷杉
项目概览
繁星间漫步
/
冷杉
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
冷杉
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d8e5f740
编写于
3月 06, 2021
作者:
陆
陆巍
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改调整模板文件以及处理方式
上级
a35b8bd8
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
184 addition
and
106 deletion
+184
-106
create_cover/cover1.tex
create_cover/cover1.tex
+10
-10
create_cover/cover2.tex
create_cover/cover2.tex
+9
-9
create_cover/create_cover.lua
create_cover/create_cover.lua
+72
-84
fir.sty
fir.sty
+4
-3
lua_tools/string.lua
lua_tools/string.lua
+89
-0
未找到文件。
create_cover/cover1.tex
浏览文件 @
d8e5f740
...
...
@@ -45,15 +45,15 @@
% 把各种参数用\newcommand定义,以方便调试、替换。注意不要与已有命令冲突
% 定义的新命令中似乎只能使用字母。
% 在parameter标注内的内容将被lua程序单独取出来作为参数与默认值使用
% lua代码识别
% parameter>>>>>到%
<<<<<parameter之间的内容
% lua代码识别
parameter>>>>>到
<<<<<parameter之间的内容
% parameter>>>>>
\newcommand
{
\PGColor
}{
white
}
% 背景颜色
\newcommand
{
\TitleOneFont
}{
fzfangsong-z02s
}
% 标题1字体
\newcommand
{
\TitleOne
}{
安顺市西秀区
}
% 标题1内容
\newcommand
{
\TitleTwoFont
}{
zcoolwenyiti
}
% 标题2字体
\newcommand
{
\TitleTwo
}{
虹山湖公园
}
% 标题2内容
\newcommand
{
\Intro
duce
OneFont
}{
fzshusong-z01s
}
% 介绍1字体
\newcommand
{
\Intro
duce
One
}{
虹山湖位于贵州省安顺市,是安顺人休闲的一个好地方。前身是一个人工湖,也叫虹山水库。2017年11月10日,批准为国家4A级旅游景区。
}
% 介绍1内容
\newcommand
{
\IntroOneFont
}{
fzshusong-z01s
}
% 介绍1字体
\newcommand
{
\IntroOne
}{
虹山湖位于贵州省安顺市,是安顺人休闲的一个好地方。前身是一个人工湖,也叫虹山水库。2017年11月10日,批准为国家4A级旅游景区。
}
% 介绍1内容
\newcommand
{
\CoverMainPic
}{
images/cover.png
}
% 封面主图片
\newcommand
{
\OrgLogoSize
}{
20mm
}
\newcommand
{
\OrgLogo
}{
images/logo.png
}
...
...
@@ -62,8 +62,8 @@
\newcommand
{
\OrgOne
}{
某某某某
}
% 组织1内容
\newcommand
{
\OrgTwoFont
}{
zcoolwenyiti
}
% 组织2字体
\newcommand
{
\OrgTwo
}{
XXXXXX XXXXXX
}
% 组织2内容
\newcommand
{
\Intro
duce
TwoFont
}{
fzshusong-z01s
}
% 介绍2字体
\newcommand
{
\Intro
duce
Two
}{
\\
XXXX:XXXXXXXXXXXX
\\
XXXX:XXXXXXXX
\\
XXXX:XXXXXXXXXXXXXX
}
% 介绍2内容
\newcommand
{
\IntroTwoFont
}{
fzshusong-z01s
}
% 介绍2字体
\newcommand
{
\IntroTwo
}{
\\
XXXX:XXXXXXXXXXXX
\\
XXXX:XXXXXXXX
\\
XXXX:XXXXXXXXXXXXXX
}
% 介绍2内容
% <<<<<parameter
...
...
@@ -75,8 +75,8 @@
\begin{titlepage}
% 在module标注内的内容将被lua程序单独取出来作为模板使用
% lua代码识别%
module>>>>>到% <<<<<modul
e之间的内容
%
modul
e>>>>>
% lua代码识别%
template>>>>>到% <<<<<templat
e之间的内容
%
templat
e>>>>>
% 设置页面背景色
\pagecolor
{
\PGColor
}
\begin{tikzpicture}
[remember picture, overlay]
...
...
@@ -90,7 +90,7 @@
}
;
% 介绍1
\node
[below of = a, xshift = -60mm, yshift = -15mm, rectangle, text width=70mm, anchor = north west]
{
\SetFont
{
\Intro
duceOneFont
}{
10
}{
\parindent
=-0.3em
\indent
\Introduce
One
}
\SetFont
{
\Intro
OneFont
}{
10
}{
\parindent
=-0.3em
\indent
\Intro
One
}
}
;
% 默认读取images文件夹内的cover.png文件作为封面图片(宽高比21:11)
\node
[rectangle, text width = 120mm, anchor = north west]
at (-28mm, -60mm)
{
...
...
@@ -114,10 +114,10 @@
\color
{
black
}
% 介绍2,字体为方正书宋体
\node
[rectangle, text width=50mm, anchor = north west]
at (120mm, -180mm)
{
\SetFont
{
\Intro
duceTwoFont
}{
10
}{
\Introduce
Two
}
\SetFont
{
\Intro
TwoFont
}{
10
}{
\Intro
Two
}
}
;
\end{tikzpicture}
% <<<<<
modul
e
% <<<<<
templat
e
\end{titlepage}
...
...
create_cover/cover2.tex
100644 → 100755
浏览文件 @
d8e5f740
...
...
@@ -46,15 +46,15 @@
% 把各种参数用\newcommand定义,以方便调试、替换。注意不要与已有命令冲突
% 定义的新命令中似乎只能使用字母。
% 在parameter标注内的内容将被lua程序单独取出来作为参数与默认值使用
% lua代码识别
% parameter>>>>>到%
<<<<<parameter之间的内容
% lua代码识别
parameter>>>>>到
<<<<<parameter之间的内容
% parameter>>>>>
\newcommand
{
\PGColor
}{
white
}
% 背景颜色
\newcommand
{
\TitleOneFont
}{
FZHei-B01S
}
% 标题1字体
\newcommand
{
\TitleOne
}{
安顺市西秀区
}
% 标题1内容
\newcommand
{
\TitleTwoFont
}{
fzfangsong-z02s
}
% 标题2字体
\newcommand
{
\TitleTwo
}{
虹山湖公园
}
% 标题2内容
\newcommand
{
\Intro
duce
OneFont
}{
fzshusong-z01s
}
% 介绍1字体
\newcommand
{
\Intro
duce
One
}{
虹山湖位于贵州省安顺市,是安顺人休闲的一个好地方。前身是一个人工湖,也叫虹山水库。2017年11月10日,批准为国家4A级旅游景区。
}
% 介绍1内容
\newcommand
{
\IntroOneFont
}{
fzshusong-z01s
}
% 介绍1字体
\newcommand
{
\IntroOne
}{
虹山湖位于贵州省安顺市,是安顺人休闲的一个好地方。前身是一个人工湖,也叫虹山水库。2017年11月10日,批准为国家4A级旅游景区。
}
% 介绍1内容
\newcommand
{
\CoverMainPicSize
}{
335mm
}
% 封面主图片尺寸
\newcommand
{
\CoverMainPic
}{
images/cover.png
}
% 封面主图片
\newcommand
{
\OrgLogoSize
}{
14mm
}
...
...
@@ -64,8 +64,8 @@
\newcommand
{
\OrgOne
}{
某某某某
}
% 组织1内容
\newcommand
{
\OrgTwoFont
}{
zcoolwenyiti
}
% 组织2字体
\newcommand
{
\OrgTwo
}{
XXXXXX XXXXXX
}
% 组织2内容
\newcommand
{
\Intro
duce
TwoFont
}{
fzshusong-z01s
}
% 介绍2字体
\newcommand
{
\Intro
duce
Two
}{
\\
XXXX:XXXXXXXXXXXX
\\
XXXX:XXXXXXXX
\\
XXXX:XXXXXXXXXXXXXX
}
% 介绍2内容
\newcommand
{
\IntroTwoFont
}{
fzshusong-z01s
}
% 介绍2字体
\newcommand
{
\IntroTwo
}{
\\
XXXX:XXXXXXXXXXXX
\\
XXXX:XXXXXXXX
\\
XXXX:XXXXXXXXXXXXXX
}
% 介绍2内容
\newcommand
{
\RemarkOne
}{
XXXX:XXXXXXXX
}
% 备注1内容
\newcommand
{
\RemarkTwo
}{
XXXX:XXXXXXXXXXXXXXXX
}
% 备注2内容
\newcommand
{
\RemarkThree
}{
XXXX:XXXXXXXXXXXXXXXX
}
% 备注3内容
...
...
@@ -85,8 +85,8 @@
\begin{titlepage}
% 在module标注内的内容将被lua程序单独取出来作为模板使用
% lua代码识别%
module>>>>>到% <<<<<modul
e之间的内容
%
modul
e>>>>>
% lua代码识别%
template>>>>>到% <<<<<templat
e之间的内容
%
templat
e>>>>>
% 设置页面背景色
\pagecolor
{
\PGColor
}
% tikzpicture后面中括号的参数让绘图时使用绝对坐标
...
...
@@ -117,7 +117,7 @@
% 介绍1
\color
{
black
}
\node
[below of = b, xshift = -50mm, yshift = -20mm, text width = 120mm, anchor = north west]
{
\SetFont
{
\Intro
duceOneFont
}{
8
}{
\parindent
=-0.4em
\indent
\Introduce
One
}
\SetFont
{
\Intro
OneFont
}{
8
}{
\parindent
=-0.4em
\indent
\Intro
One
}
}
;
% 定义等腰三角形样式
\tikzset
{
...
...
@@ -147,7 +147,7 @@ rotate = 180, minimum size = 171mm, path picture = {
\node
[right of = e, xshift = 50mm, text width = 60mm]
{
\RemarkTwo
}
;
\node
[right of = e, xshift = 120mm, text width = 60mm]
{
\RemarkThree
}
;
\end{tikzpicture}
% <<<<<
modul
e
% <<<<<
templat
e
\end{titlepage}
...
...
create_cover/create_cover.lua
浏览文件 @
d8e5f740
...
...
@@ -10,109 +10,97 @@
-- 定义CreateCover类
CreateCover
=
{
code
=
""
,
number
=
"1"
}
function
CreateCover
:
new
(
o
,
str
)
function
CreateCover
:
new
(
o
,
str
,
number
)
o
=
o
or
{}
setmetatable
(
o
,
self
)
setmetatable
(
o
,
self
,
self
)
self
.
__index
=
self
self
.
code
=
str
self
.
number
=
number
return
o
end
-- @brief 提取关键字内容
-- @param key 关键字
-- @param str 被提取字符串
-- @return 返回关键字对应内容
function
GetValue
(
key
,
str
,
default
)
local
str1
=
string.gsub
(
str
,
".*,%s*"
..
key
..
"%s*=%s*"
,
""
)
if
(
str1
==
str
)
then
--print(key .. "\n")
--print(str1 .. "\n\n")
return
default
else
return
string.gsub
(
str1
,
"%s*,.*"
,
""
)
end
-- @brief 记录日志
-- @param monitoring_data 监控数据
-- @param file 要保存的日志文件
-- @parm method 文件写入方式,0表示覆盖写入,1表示追加写入
function
Logger
(
monitoring_data
,
file
,
method
)
local
str1
=
monitoring_data
..
"
\n\n
"
local
meth
=
method
==
0
and
"w"
or
"a"
local
log
=
io.open
(
file
,
meth
)
log
:
write
(
str1
)
log
:
close
()
end
-- @brief 生成LaTeX封面代码
function
CreateCover
:
Create
()
-- 前后添加逗号,规范数据流格式,保证语句的适用性。
local
user_input
=
", "
..
self
.
code
..
","
-- 获取封面编号(对于特殊字符需要加上%符号来匹配)
local
cover_number
=
GetValue
(
"cover%-number"
,
user_input
,
"1"
)
-- 单独调试lua文件时的require路径与LaTeX调用时的路径是不一样的
--package.path = "fir/lua_tools/string.lua"
--require("FirString")
require
(
"fir/lua_tools/string"
)
-- 为配合后面的工作,需要把用户输入的内容中的单引号换成双引号
-- 之所以用户输入时要用单引号,是因为双引号在LaTeX传入lua数据时另有别的意思
local
user_input
=
string.gsub
(
self
.
code
,
"'"
,
'"'
)
-- Logger(user_input, "test1.log", 0)
-- 读取模板文件内容
-- local fp = io.open("fir/create_cover/cover.tex", "r")
local
fp
=
io.open
(
"cover"
..
cover_number
..
".tex"
,
"r"
)
local
fp
=
io.open
(
"fir/create_cover/cover"
..
self
.
number
..
".tex"
,
"r"
)
local
template
=
fp
:
read
(
"*a"
)
fp
:
close
()
--
print
(
"cover"
..
cover_number
..
".tex"
)
print
(
template
)
do
return
end
-- 获取背景色
local
pgcolor
=
GetValue
(
"pgcolor"
,
info
,
"white"
)
-- 获取标题1内容
local
title1
=
GetValue
(
"title1"
,
info
,
" "
)
-- 获取标题1字体。默认为方正仿宋体
local
title1_font
=
GetValue
(
"title1%-font"
,
info
,
"fzfangsong-z02s"
)
-- 获取标题2内容
local
title2
=
GetValue
(
"title2"
,
info
,
" "
)
-- 获取标题2字体。默认为站酷文艺体
local
title2_font
=
GetValue
(
"title2%-font"
,
info
,
"zcoolwenyiti"
)
-- 获取介绍1内容
local
intro1
=
GetValue
(
"intro1"
,
info
,
" "
)
-- 获取介绍1字体。默认为方正书宋体
local
intro1_font
=
GetValue
(
"intro1%-font"
,
info
,
"fzshusong-z01s"
)
-- 获取组织颜色
local
org_color
=
GetValue
(
"org%-color"
,
info
,
"OliveGreen"
)
-- 获取组织1内容
local
org1
=
GetValue
(
"org1"
,
info
,
" "
)
-- 获取组织1字体。默认为站酷文艺体
local
org1_font
=
GetValue
(
"org1%-font"
,
info
,
"zcoolwenyiti"
)
-- 获取组织2内容
local
org2
=
GetValue
(
"org2"
,
info
,
" "
)
-- 获取组织2字体。默认为站酷文艺体
local
org2_font
=
GetValue
(
"org2%-font"
,
info
,
"zcoolwenyiti"
)
-- 获取组织2字体大小
local
org2_size
=
GetValue
(
"org2%-size"
,
info
,
"18"
)
-- 获取介绍2内容
local
intro2
=
GetValue
(
"intro2"
,
info
,
" "
)
-- 获取介绍2字体。默认为方正书宋体
local
intro2_font
=
GetValue
(
"intro2%-font"
,
info
,
"fzshusong-z01s"
)
-- 读取create_cover.sty文件内容
local
fp
=
io.open
(
"fir/create_cover/cover.tex"
,
"r"
)
-- local fp = io.open("cover.tex", "r")
local
contents
=
fp
:
read
(
"*a"
)
fp
:
close
()
-- 读取模板内容中的参数块
local
parm_block
=
string.match
(
template
,
"%% parameter>>>>>.*%% <<<<<parameter"
)
-- parm_block = string.gsub(parm_block, "\\newcommand{", "")
-- 定义并初始化参数列表二维数组。这里控制了支持的参数数量。
local
parm_list
=
{}
for
i
=
0
,
100
do
parm_list
[
i
]
=
{}
for
j
=
0
,
1
do
parm_list
[
i
][
j
]
=
""
end
end
-- 逐一读取参数块中的参数,并填入参数列表数组中。
local
parm_number
=
FirString
.
Count
(
parm_block
,
"
\\
newcommand"
)
for
i
=
1
,
parm_number
do
local
parm
=
FirString
.
SubString
(
parm_block
,
"
\\
newcommand{\\"
,
"}"
,
i
)
parm_list
[
i
][
0
]
=
parm
parm_list
[
i
][
1
]
=
FirString
.
SubString
(
parm_block
,
"}{"
,
"}"
,
i
)
-- print(i, parm_list[i][0] .. " " .. parm_list[i][1], "\n")
i
=
i
+
1
end
-- 读取用户输入的参数并替换参数列表数组中的对应值
for
i
=
1
,
FirString
.
Count
(
user_input
,
":"
)
do
local
parm
=
FirString
.
GetKeyByOrder
(
user_input
,
i
)
local
value
=
FirString
.
GetValueByOrder
(
user_input
,
i
)
--print(i, param, value)
for
i
=
1
,
parm_number
do
if
(
parm_list
[
i
][
0
]
==
parm
)
then
parm_list
[
i
][
1
]
=
value
break
end
end
end
-- 提取模板文件中实际的模板内容
template
=
string.gsub
(
template
,
".*%% template>>>>>"
,
""
)
template
=
string.gsub
(
template
,
"%% <<<<<template.*"
,
""
)
-- 把模板文件中对应的参数替换成实际值
for
i
=
1
,
parm_number
do
--print(parm_list[i][0], parm_list[i][1])
template
=
string.gsub
(
template
,
"
\\
"
..
parm_list
[
i
][
0
],
parm_list
[
i
][
1
])
end
-- 部分替换中会加入避免混淆的字符。
-- 例如pgcolor,如果不加入“=“,就会与“\pgcolor“混淆
contents
=
string.gsub
(
contents
,
"{pgcolor}"
,
"{"
..
pgcolor
..
"}"
)
-- 替换背景色
contents
=
string.gsub
(
contents
,
"{title1}"
,
"{"
..
title1
..
"}"
)
-- 替换标题1
contents
=
string.gsub
(
contents
,
"title1%-font"
,
title1_font
)
-- 替换标题1字体
contents
=
string.gsub
(
contents
,
"{title2}"
,
"{"
..
title2
..
"}"
)
-- 替换标题2
contents
=
string.gsub
(
contents
,
"title2%-font"
,
title2_font
)
-- 替换标题2字体
contents
=
string.gsub
(
contents
,
"{intro1}"
,
"{"
..
intro1
..
"}"
)
-- 替换介绍1
contents
=
string.gsub
(
contents
,
"intro1%-font"
,
intro1_font
)
-- 替换介绍1字体
contents
=
string.gsub
(
contents
,
"org%-color"
,
org_color
)
-- 替换组织文字颜色
contents
=
string.gsub
(
contents
,
"{org1}"
,
"{"
..
org1
..
"}"
)
-- 替换组织1
contents
=
string.gsub
(
contents
,
"org1%-font"
,
org1_font
)
-- 替换组织1字体
contents
=
string.gsub
(
contents
,
"{org2}"
,
"{"
..
org2
..
"}"
)
-- 替换组织2
contents
=
string.gsub
(
contents
,
"org2%-font"
,
org2_font
)
-- 替换组织2字体
contents
=
string.gsub
(
contents
,
"org2%-size"
,
org2_size
)
-- 替换组织2字体大小
contents
=
string.gsub
(
contents
,
"{intro2}"
,
"{"
..
intro2
..
"}"
)
-- 替换介绍2
contents
=
string.gsub
(
contents
,
"intro2%-font"
,
intro2_font
)
-- 替换介绍2字体
print
(
template
)
-- 写入文件
local
fp1
=
io.open
(
"cover_temp.tex"
,
"w"
)
fp1
:
write
(
contents
)
fp1
:
write
(
template
)
fp1
:
close
()
end
local
cover
=
CreateCover
:
new
(
nil
,
"
"
)
cover
:
Create
()
--local cover = CreateCover:new(nil, '"TitleOne": "编译原理", "TitleTwo": "学习笔记", "OrgOne": "湖畔机器人", "OrgTwo": "LAKESIDE ROBOTICS"', "1
")
--
cover:Create()
\ No newline at end of file
fir.sty
浏览文件 @
d8e5f740
...
...
@@ -23,6 +23,7 @@
\RequirePackage
{
luacode
}
% lua支持
\RequirePackage
{
xcolor
}
\RequirePackage
{
tikz
}
\usetikzlibrary
{
shapes.geometric
}
% ====================== 定义 ======================
...
...
@@ -35,11 +36,11 @@
}
% 封面创建命令
\newcommand
{
\CreateCover
}
[
1
][]
{
\newcommand
{
\CreateCover
}
[
2
][]
{
\luaexec
{
require("fir/create
_
cover/create
_
cover")
local cover = CreateCover:new(nil, "#1")
local cover = CreateCover:new(nil, "#1"
, "#2"
)
tex.sprint(cover:Create())
}
\include
{
cover
_
temp
}
\include
{
cover
_
temp
}
}
\ No newline at end of file
lua_tools/string.lua
0 → 100755
浏览文件 @
d8e5f740
--[[
@file string.lua
@brief lua字符串处理函数库
@copyright MIT
@author 陆巍
@version 1.0.0
@date 2021-03-05
--]]
-- 定义字符串处理模块
FirString
=
{}
-- @brief 统计指定字符串在字符串中出现的次数
-- @param str 原字符串
-- @param target_str 目标字符串
-- @return 返回次数
function
FirString
.
Count
(
str
,
target_str
)
local
count
=
0
for
i
in
string.gmatch
(
str
,
target_str
)
do
count
=
count
+
1
end
return
count
end
-- @brief 读取指定字符串边界内的字符
-- @param str 被提取字符串
-- @param start_str 起始字符串
-- @param end_str 结束字符串
-- @param n 第几次出现
-- @return 返回查到的字符串
-- @note 返回字符串的左右空格将被清除
function
FirString
.
SubString
(
str
,
start_str
,
end_str
,
n
)
if
(
n
<=
0
)
then
return
"Error: Parameter n is invalid."
end
str
=
string.gsub
(
str
,
".-"
..
start_str
..
"%s*"
,
""
,
n
)
str
=
string.gsub
(
str
,
end_str
..
".*"
,
""
)
return
str
end
-- @brief 查找某个字符串第n次出现的位置
-- @param str 被提取字符串
-- @param n 顺序号
-- @return 返回查到的位置
function
FirString
.
FindByOrder
(
str
,
target_str
,
n
)
local
i
=
0
local
site
=
0
while
(
i
<
n
)
do
site
=
string.find
(
str
,
target_str
,
site
+
1
)
i
=
i
+
1
end
return
site
end
-- @brief 通过序号获取类JSON数据的键
-- @param str 被提取字符串
-- @param n 顺序号
-- @return 返回查到的键
function
FirString
.
GetKeyByOrder
(
str
,
n
)
if
(
n
<=
0
)
then
return
"Error: Parameter n is invalid."
end
local
site
=
FirString
.
FindByOrder
(
str
,
":"
,
n
)
str
=
string.sub
(
str
,
1
,
site
)
str
=
string.gsub
(
str
,
'"%s*:'
,
''
)
str
=
string.gsub
(
str
,
'.*"'
,
''
)
return
str
end
-- @brief 通过序号获取类JSON数据的值
-- @param str 被提取字符串
-- @param n 顺序号
-- @return 返回查到的值
function
FirString
.
GetValueByOrder
(
str
,
n
)
if
(
n
<=
0
)
then
return
"Error: Parameter n is invalid."
end
local
site
=
FirString
.
FindByOrder
(
str
,
":"
,
n
)
str
=
string.sub
(
str
,
site
)
str
=
string.gsub
(
str
,
':%s*"'
,
''
)
str
=
string.gsub
(
str
,
'".*'
,
''
)
return
str
end
return
FirString
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录