This commit is contained in:
sharings 2025-07-26 12:43:01 +00:00
commit 1e2ca5a6fc
71 changed files with 3330 additions and 0 deletions

View file

@ -0,0 +1,20 @@
-- https://github.com/L3MON4D3/LuaSnip/wiki/Cool-Snippets#endless-list
local rec_ls
rec_ls = function()
return sn(nil, {
c(1, {
-- important!! Having the sn(...) as the first choice will cause infinite recursion.
t({""}),
-- The same dynamicNode as in the snippet (also note: self reference).
sn(nil, {t({"", "\t\\item "}), i(1), d(2, rec_ls, {})}),
}),
});
end
return {
s(";endlessitem", {
t({"\\begin{itemize}",
"\t\\item "}), i(1), d(2, rec_ls, {}),
t({"", "\\end{itemize}"}), i(0)
})
}

View file

@ -0,0 +1,40 @@
-- https://github.com/L3MON4D3/LuaSnip/wiki/Cool-Snippets#tabular
table_node= function(args)
local tabs = {}
local count
table = args[1][1]:gsub("%s",""):gsub("|","")
count = table:len()
for j=1, count do
local iNode
iNode = i(j)
tabs[2*j-1] = iNode
if j~=count then
tabs[2*j] = t" & "
end
end
return sn(nil, tabs)
end
rec_table = function ()
return sn(nil, {
c(1, {
t({""}),
sn(nil, {t{"\\\\",""} ,d(1,table_node, {ai[1]}), d(2, rec_table, {ai[1]})})
}),
});
end
return {
s(";table", {
t"\\begin{tabular}{",
i(1,"0"),
t{"}",""},
d(2, table_node, {1}, {}),
d(3, rec_table, {1}),
t{"","\\end{tabular}"}
}),
}

View file

@ -0,0 +1,102 @@
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return {
s(
{ trig = ";dcenvelope", dscr = "A LaTeX equation environment" },
fmta(
[[
% https://en.wikibooks.org/wiki/LaTeX/Letters#Envelopes
% https://tex.stackexchange.com/questions/268693/how-do-you-print-c4-envelopes
\documentclass{letter}
\usepackage{geometry}
\geometry{paperheight=9.25in,paperwidth=4.13in}
\usepackage{graphics}
\usepackage{envlab}
\usepackage[AutoFallBack=true]{xeCJK}
\setCJKmainfont<>
% from envlab
\SetEnvelope{9.25in}{4.13in}
% from envlab
\setlength{\ToAddressTopMargin}{0in} %Arbitrarily decided by me
% from envlab
\setlength{\ToAddressLeftMargin}{1in} %Arbitrarily decided by me
% from envlab
\makelabels
\begin{document}
\startlabels
% from envlab
\mlabel
{% This "%" is required to make alignment right
%
% Sender Address
%
% append \\ at the end of the line before inserting newline
%
% e.g. Title\\
% Address line1\\
% Address line2\\
% Address line3
<>
}
{% This "%" is required to make alignment right
%
% Reciever Address
%
% append \\ at the end of the line before inserting newline
%
% e.g. Title\\
% Address line1\\
% Address line2\\
% Address line3
<>
% if print with lpr use command "lpr -o media=EnvYou4"
}
\end{document}
]],
{
c(1, {
t({
"{Source Han Serif TC}",
"\\newCJKfontfamily\\secondaryfont{Source Han Sans TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
t({
"{Source Han Sans TC}",
"\\newCJKfontfamily\\secondaryfont{Source Han Serif TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
t({
"[Path=\\string~/.local/share/fonts/",
",UprightFeatures = {FontIndex=13}",
",BoldFeatures = {FontIndex=28}",
"]{SourceHanSerif.ttc}",
"\\newCJKfontfamily[Path=\\string~/.local/share/fonts/",
" ,UprightFeatures = {FontIndex=28}",
" ,BoldFeatures = {FontIndex=38}",
"]\\secondaryfont{Source Han Sans TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
t({
"[Path=\\string~/.local/share/fonts/",
",UprightFeatures = {FontIndex=28}",
",BoldFeatures = {FontIndex=38}",
"]{SourceHanSans.ttc}",
"\\newCJKfontfamily[Path=\\string~/.local/share/fonts/",
",UprightFeatures = {FontIndex=13}",
",BoldFeatures = {FontIndex=28}",
"]\\secondaryfont{Source Han Serif TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
}),
i(3, "% Sender Address"),
i(2, "% Reciever Address"),
}
),
{ condition = line_begin } -- set condition in the `opts` table
),
}

View file

@ -0,0 +1,74 @@
local helpers = require("luasnip-helper-funcs")
local get_visual = helpers.get_visual
return {
s(
{ trig = ";dcinit", snippetType = "snippet" },
fmta(
[[
\documentclass[<>]{<>}
\usepackage[<>]{geometry}
\usepackage[AutoFallBack=true]{xeCJK}
\setCJKmainfont<>
\begin{document}
<><>
\end{document}
]],
{
c(1, {
t(""),
t("a4paper"),
t("letter"),
t("20pt"),
}),
c(2, {
t("article"),
t("extarticle"),
t("report"),
t("moderncv"),
}),
c(3, {
t(""),
t("margin=3cm"),
t("top=3cm,bottom=3cm,left=3cm,right=3cm"),
}),
c(4, {
t({
"{Source Han Serif TC}",
"\\newCJKfontfamily\\secondaryfont{Source Han Sans TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
t({
"{Source Han Sans TC}",
"\\newCJKfontfamily\\secondaryfont{Source Han Serif TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
t({
"[Path=\\string~/.local/share/fonts/",
",UprightFeatures = {FontIndex=13}",
",BoldFeatures = {FontIndex=28}",
"]{SourceHanSerif.ttc}",
"\\newCJKfontfamily[Path=\\string~/.local/share/fonts/",
" ,UprightFeatures = {FontIndex=28}",
" ,BoldFeatures = {FontIndex=38}",
"]\\secondaryfont{Source Han Sans TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
t({
"[Path=\\string~/.local/share/fonts/",
",UprightFeatures = {FontIndex=28}",
",BoldFeatures = {FontIndex=38}",
"]{SourceHanSans.ttc}",
"\\newCJKfontfamily[Path=\\string~/.local/share/fonts/",
",UprightFeatures = {FontIndex=13}",
",BoldFeatures = {FontIndex=28}",
"]\\secondaryfont{Source Han Serif TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
}),
d(5, get_visual, {}, { user_args = { "Content here" } }),
i(0),
}
)
),
}

View file

@ -0,0 +1,30 @@
local line_begin = require("luasnip.extras.expand_conditions").line_begin
return {
s(
{ trig = ";dcwatermark", dscr = "Top-right corner watermark" },
fmta(
[[
\documentclass[a4paper]{article}
\usepackage[top=.2in,right=.2in]{geometry}
\usepackage{xcolor}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
% switch off page number
% https://tex.stackexchange.com/questions/7355/how-to-suppress-page-number
\pagenumbering{gobble}
% https://superuser.com/questions/280659/how-can-i-apply-a-watermark-on-every-page-of-a-pdf-file
% pdftk original.pdf stamp watermark.pdf output final.pdf
\hfill {\Large \textcolor{red}{``<>''}}
\end{document}
]],
{
i(1, "Insert watermark"),
}
),
{ condition = line_begin } -- set condition in the `opts` table
),
}

View file

@ -0,0 +1,72 @@
local line_begin = require("luasnip.extras.expand_conditions").line_begin
local helpers = require("luasnip-helper-funcs")
local get_visual = helpers.get_visual
local mkscbs = helpers.make_single_curly_bracket_snippets
local mkss = helpers.make_scope_snippets
-- mkscbs ("snippetType", "trig", "command", "desc")
return
-- https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#lua
-- First list of snippets (snippetType = "snippet") start
{
mkscbs("snippet", ";tt", "texttt", "teletypefont"),
mkscbs("snippet", ";ti", "textit", "italic shape"),
mkscbs("snippet", ";bf", "textbf", "bold"),
mkscbs("snippet", ";em", "emph", "emphasis"),
mkscbs("snippet", ";em", "emph", "emphasis"),
mkscbs("snippet", ";sf", "sfont", "secondary font"),
s(
{ trig = ";url", dscr = "The hyperref package's href{}{} command (for url links)" },
fmta("\\href{<>}{<>}", {
d(1, get_visual, { 1 }, { user_args = { "url" } }),
i(2, "display name"),
})
),
s(
-- https://en.wikibooks.org/wiki/LaTeX/Paragraph_Formatting#Verbatim_text
{ trig = ";vb", dscr = "Expands 'vb' into '\\verb++' (verbatim phrase, + as delimiters (can be changed))" },
fmta("\\verb<><><>", { i(1, "+"), d(2, get_visual, {}, { user_args = { "verbatim phrase" } }), rep(1) })
),
s(
{ trig = ";begin", dscr = "A LaTeX equation environment" },
fmta(
[[
\begin{<>}
<><>
\end{<>}
]],
-- The insert node is placed in the <> angle brackets
{ i(1), d(2, get_visual, {}, { user_args = { "Content here" } }), i(0), rep(1) }
),
{ condition = line_begin } -- set condition in the `opts` table
),
s(
{ trig = ";ff", dscr = "Expands 'ff' into '\\frac{}{}'" },
fmt("\\fanc{<>}{<>}", { i(1), i(2) }, { delimiters = "<>" })
),
-- Example use of insert node placeholder text
s({ trig = ";s", desc = "square bracket" }, fmta("\\<>[<>]", { i(1, "command"), d(2, get_visual) })),
s({ trig = ";c", desc = "curly bracket" }, fmta("\\<>{<>}", { i(1, "command"), d(2, get_visual) })),
s({ trig = ";cc", desc = "curly bracket + curly bracket" }, fmta("\\<>{<>}{<>}", { i(1, "command"), i(3), i(2) })),
s({ trig = ";sc", desc = "square bracket + curly bracket" }, fmta("\\<>[<>]{<>}", { i(1, "command"), i(3), i(2) })),
-- s(
-- { trig = ";tt", dscr = "Expands 'tt' into '\\texttt{}' (teletypefont family)" },
-- fmta("\\texttt{<>}", { d(1, get_visual, {}, { user_args = { "teletypefont" } }) })
-- ),
-- s(
-- { trig = ";ti", dscr = "Expands 'ti' into '\\textit{}' (italic shape)" },
-- fmta("\\textit{<>}", { d(1, get_visual, {}, { user_args = { "italic shape" } }) })
-- ),
-- s(
-- { trig = ";bf", dscr = "Expands 'bf' into '\\textbf{}' (bold)" },
-- fmta("\\textbf{<>}", { d(1, get_visual, {}, { user_args = { "bold" } }) })
-- ),
-- s(
-- { trig = ";em", dscr = "Expands 'em' into '\\emph{}' (emphasis)" },
-- fmta("\\emph{<>}", { d(1, get_visual, {}, { user_args = { "emphasis" } }) })
-- ),
},
-- First list of snippets (snippetType = "snippet") end
-- Second list of snippets (snippetType = "autosnippet") start
{}
-- Second list of snippets (snippetType = "autosnippet") end

View file

@ -0,0 +1,75 @@
return {
s(
";updarkmode",
t({
"\\usepackage{xcolor}",
"\\pagecolor[rgb]{0.1,0.1,0.1}",
"\\color[rgb]{1,1,1}",
})
),
s(";upurlpackage", t("\\usepackage{hyperref}")),
-- % https://old.reddit.com/r/LaTeX/comments/m8frij/aligning_text_across_lines/
-- % allign dates in working experience
-- for \brlap or \stackunder or \bllap
s(";upstack", t("\\usepackage{stackengine}")),
-- % for \CurrentLineWidth
s(";uptabto", t("\\usepackage{tabto}")),
-- % https://tex.stackexchange.com/questions/5036/how-to-prevent-latex-from-hyphenating-the-entire-document
-- % disable hyphenation at the edge
s(";upnohyphen", t("\\usepackage[none]{hyphenat}")),
s(";upinpututf8", t("\\usepackage[utf8]{inputenc}")),
s(";up", fmta("\\usepackage[<>]{<>}", { i(2), i(1) })),
-- Help using xeCJK
-- https://tex.stackexchange.com/questions/510853/using-one-xecjk-font-family-on-english-and-chinese-at-the-same-time
-- https://tex.stackexchange.com/questions/264265/defining-subfamilies-for-a-font/264275#264275
s(
";upxecjk",
fmta(
[[
\usepackage[AutoFallBack=true]{xeCJK}
\setCJKmainfont<>
]],
{
c(1, {
t({
"{Source Han Serif TC}",
"\\newCJKfontfamily\\secondaryfont{Source Han Sans TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
t({
"{Source Han Sans TC}",
"\\newCJKfontfamily\\secondaryfont{Source Han Serif TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
t({
"[Path=\\string~/.local/share/fonts/",
",UprightFeatures = {FontIndex=13}",
",BoldFeatures = {FontIndex=28}",
"]{SourceHanSerif.ttc}",
"\\newCJKfontfamily[Path=\\string~/.local/share/fonts/",
" ,UprightFeatures = {FontIndex=28}",
" ,BoldFeatures = {FontIndex=38}",
"]\\secondaryfont{Source Han Sans TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
t({
"[Path=\\string~/.local/share/fonts/",
",UprightFeatures = {FontIndex=28}",
",BoldFeatures = {FontIndex=38}",
"]{SourceHanSans.ttc}",
"\\newCJKfontfamily[Path=\\string~/.local/share/fonts/",
",UprightFeatures = {FontIndex=13}",
",BoldFeatures = {FontIndex=28}",
"]\\secondaryfont{Source Han Serif TC}",
"\\newcommand*{\\sfont}[1]{{\\secondaryfont #1}}",
}),
}),
}
)
),
}