提交 45c1ca11 编写于 作者: 陆巍

初次提交

上级
MIT License
Copyright (c) 2021 陆巍
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
% 设置页面布局
\newgeometry{left = -8.5mm, top = 0mm, bottom = -7mm}
% 设置页面背景色
\pagecolor{pgcolor}
\begin{tikzpicture}
\node(a)[rectangle, text width = 120mm] at (3.5, -0.5){
% 标题1
\SetFont{title1-font}{40}{title1}\\
% 标题2
\SetFont{title2-font}{40}{title2}
};
% 介绍1
\node[below of = a, xshift = -90, yshift = -70, rectangle, text width=5.5cm] {
\SetFont{intro1-font}{10}{intro1}
};
% 默认读取images文件夹内的cover.png文件作为封面图片(宽高比21:11)
\node[rectangle, text width = 120mm] at (0, -12.5){
\includegraphics[width = 215mm]{images/cover.png}
};
% 绘制左侧竖条
\fill[fill = LightGray](-47mm, 20mm) rectangle (-45mm, -260mm);
% 标志,默认读取images文件夹内的logo.png文件。(宽高比1:1)
\node[rectangle, text width = 120mm] at (3.5, -22){
\includegraphics[width = 23mm]{images/logo.png}
};
% 组织名称
\color{org-color}
\node[rectangle, text width = 120mm] at (6, -21.8){
% 名称1,字体为站酷文艺体
\SetFont{org1-font}{30}{org1}\\[3mm]
% 名称2,字体为站酷文艺体
\SetFont{org2-font}{org2-size}{org2}
};
\color{black}
% 介绍2,字体为方正书宋体
\node[rectangle, text width=50mm] at (12, -20) {
\SetFont{intro2-font}{10}{intro2}
};
\end{tikzpicture}
--[[
@file create_cover.lua
@brief LaTeX封面代码生成文件
@copyright MIT
@author 陆巍
@version 1.0.0
@date 20221-02-27
--]]
-- 定义CreateCover类
CreateCover = {
code = "",
}
function CreateCover:new(o, str)
o = o or {}
setmetatable(o, self)
self.__index = self
self.code = str
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
end
-- @brief 生成LaTeX封面代码
function CreateCover:Create()
-- 前后添加逗号,规范数据流格式,保证语句的适用性。
local info = ", " .. self.code .. ","
-- 获取封面编号(对于特殊字符需要加上%符号来匹配)
local cover_number = GetValue("cover%-number", info, "1")
-- 获取背景色
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()
-- 部分替换中会加入避免混淆的字符。
-- 例如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字体
-- 写入文件
local fp1 = io.open("cover_temp.tex", "w")
fp1:write(contents)
fp1:close()
end
--local cover = CreateCover:new(nil, "")
--cover:Create()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% fir.sty
%
% 封面生成包
% 生成LaTeX文档封面。
%
% License: MIT
% Author: 陆巍
% Email: willard.lu@outlook.com
% Version: 1.0.0
% Date: 2021-02-26
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ====================== 环境设置 ======================
% 下面两行是声明类的固定格式
\NeedsTeXFormat{LaTeX2e}[2007/10/19]
\ProvidesPackage{fir}[2021/02/22]
% 把以下三个库加入xcolor中(调用时)
\PassOptionsToPackage{dvipsnames, svgnames, x11names}{xcolor}
\RequirePackage{luacode}% lua支持
\RequirePackage{xcolor}
\RequirePackage{tikz}
% ====================== 定义 ======================
% 定义指定字体名称与大小的文字输出命令
% 第1个参数:字体名称
% 第2个参数:字体大小
% 第3个参数:文本内容
\newcommand{\SetFont}[3]{
\setCJKfamilyfont{font1}{#1} \CJKfamily{font1}\fontsize{#2}{#2}{\selectfont #3}
}
% 封面创建命令
\newcommand{\CreateCover}[1][]{
\luaexec{
require("fir/create_cover/create_cover")
local cover = CreateCover:new(nil, "#1")
tex.sprint(cover:Create())
}
\include{cover_temp}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册