BNU-FZH

fengzhenhua@outlook.com

git是当前最常见的版本控制工具,但出现以下情况时,往往需要清空commits历史记录:

  • commits记录占用空间过大甚至远远超过版本控制文件本身大小,进行云端代码管理时会受制于空间限制,无法继续更新
  • 历史记录中存在敏感信息,需要清理

清理commits历史记录的核心思想是,直接删除本地的.git目录,重新建立git仓库并与远程仓库建立链接,采用强制提交的方式覆盖远程仓库的commits记录。

下面是一段示例,参数说明:

  • $REPO_DIR 表示需要处理的Git仓库本地目录
  • git@github.com:xxxx/$REPO_DIR.git 表示远程仓库地址

进入本地仓库,删除.git目录

1
2
cd $REPO_DIR
rm -rf .git

重新初始化

1
2
git init
git branch -m main

由于Gitlab仓库的默认分支名为main,而仓库初始化默认为master, 所以需要重命名为main.

添加commit

1
2
git add .
git commit -m "restart git commit"

添加远程仓库链接

设置远程仓库代号为origin, 则

1
git remote add orign git@github.com:xxxx/$REPO_DIR.git

注意,此时可用git remote -v检查远程仓库的设置。

强制提交到master分支,覆盖远程仓库的commits历史提交记录

1
2
3
git push -f origin master
or
git push --force origin master

追踪上游分支

1
git push --set-upstream origin main

如果不设置上游分支,再次提交时的commits不能确定跟踪变化,所以不能正常提交博客文章,于是这是一个必须的操作。

参考文章

清空Github仓库的commits历史记录

作为一个理科生,终生都离不开数学公式。而LaTeX绝对是处理数学公式的王者,在编辑LaTeX中的众多工具中,使用vim或neovim配合编辑LaTeX的插件又是王者中的王者。在众多的插件中,vim-latexvimtex是网络上提到最多的,也是使用者最多的插件,但是这两者该如何选择呢?经过本人的实践,最终选择了vim-latex.

选择依据分析

众多网络文章都提到了插件vimtex, 按其官方介绍:VimTeX is a modern Vim and Neovim filetype and syntax plugin for LaTeX files. , 或许就是这个modern让许多人选择了它。诚然vimtex是一个优秀的插件,我们来看一下它提供的功能(引用其README.md):

  • Document compilation with latexmk, latexrun, tectonic, or arara
  • LaTeX log parsing for quickfix entries using
  • Compilation of selected part of document
  • Support for several PDF viewers with forward search
  • Completion of
    • citations
    • labels
    • commands
    • file names for figures, input/include, includepdf, includestandalone
    • glossary entries
    • package and documentclass names based on available .sty and .cls files
  • Document navigation through
    • table of contents
    • table of labels
    • proper settings for 'include', 'includexpr', 'suffixesadd' and 'define', which among other things
      • allow :h include-search and :h definition-search
      • give enhanced gf command
  • Easy access to (online) documentation of packages
  • Word count (through texcount)
  • Motions (link to GIF demonstrations)
    • Move between section boundaries with [[, [], ][, and ]]
    • Move between environment boundaries with [m, [M, ]m, and ]M
    • Move between math environment boundaries with [n, [N, ]n, and ]N
    • Move between frame environment boundaries with [r, [R, ]r, and ]R
    • Move between comment boundaries with [* and ]*
    • Move between matching delimiters with %
  • Text objects (link to GIF demonstrations)
    • ic ac Commands
    • id ad Delimiters
    • ie ae LaTeX environments
    • i$ a$ Math environments
    • iP aP Sections
    • im am Items
  • Other mappings (link to GIF demonstrations)
    • Delete the surrounding command, environment or delimiter with dsc/dse/ds$/dsd
    • Change the surrounding command, environment or delimiter with csc/cse/cs$/csd
    • Toggle starred command or environment with tsc/tse
    • Toggle inline and displaymath with ts$
    • Toggle between e.g. () and \left(\right) with tsd
    • Toggle (inline) fractions with tsf
    • Close the current environment/delimiter in insert mode with ]]
    • Add \left ... \right) modifiers to surrounding delimiters with <F8>
    • Insert new command with <F7>
    • Convenient insert mode mappings for faster typing of e.g. maths
    • Context menu on citations (e.g. \cite{...}) mapped to <cr>
  • Improved folding (:h 'foldexpr')
  • Improved indentation (:h 'indentexpr')
  • Syntax highlighting
    • A consistent core syntax specification
    • General syntax highlighting for several popular LaTeX packages
    • Nested syntax highlighting for several popular LaTeX packages
    • Highlight matching delimiters
  • Support for multi-file project packages

而插件vim-latex(又称latex-suite), 按vimtexREADME.md

The main difference between VimTeX and LaTeX-Suite (aka vim-latex) is probably that VimTeX does not try to implement a full fledged IDE for LaTeX inside Vim. E.g.:

  • VimTeX does not provide a full snippet feature, because this is better handled by UltiSnips or neosnippet or similar snippet engines.
  • VimTeX builds upon Vim principles: It provides text objects for environments, inline math, it provides motions for sections and paragraphs
  • VimTeX uses latexmk, latexrun, tectonic or arara for compilation with a callback feature to get instant feedback on compilation errors
  • VimTeX is very modular: if you don't like a feature, you can turn it off.

这两个插件有相同的部分,比如说输入希腊字母,vim-latex在任何模式下都可以输出对应的希腊字母命令,而vimtex在数学模式中才输出希腊字母,相较而言vimtex更加保险一些,但是对于一个熟悉LaTeX的人来讲,这个事情都是知道的,影响不大,只能说vimtex更加细致一点。而vim-latex提供了完整的LaTeX的输入语法,同时提供了<++>标记方法,可以使用Ctrl+j快速的移动光标,这点是vimtex所无法比拟的。按vimtex的说法,vimtex把补全的任务交给了其他插件,但是就专业性和速度上讲,vim-latex绝对领先。

vimtex提供的较好的特性是光标在各环境中移动,这点是vim-latex不具备的功能。但是vimneovim的特性,使用搜索功能或数字键加hjkl方式移动光标,好像vimtex也没有占据足够的优势。

vimtex方便的更改环境功能,例如cse可以方便的更换为新的环境,但是vim-latex也可以使用<S-F5>快捷键快速更换环境,再则考虑到编写环境前作者肯定是规划好的环境,所以更改环境是一个低概率事件。此处注意,Neovim中同时按下组键<S+F5>(也就是Shift+F5)返回的是F17,并不能获得vim-latex所需的组合键<S-F5>!! 具体请参考keycode in terminal for vim&neovim, 于是做出修改:

~/.config/nvim/init.vim
1
2
3
4
map <F17> <S-F5>
imap <F17> <S-F5>
map <F19> <S-F7>
imap <F19> <S-F7>

修改完毕,在neovim中可以正常使用环境或命令的替换。很多人选择vimtex的一个重要原因是其可以配置增量编译,实现时时查看结果,但是LaTeX的精神本身就是!对于一个熟悉LaTeX的人来讲随时关注结果并不是必须的,除非公式比较复杂,而这只需要编译一下看看结果即可。时时编译的代价就是电脑消耗更多的资源,对于我的笔记本来说,风扇一直转发出的噪音会干扰我的写作思维。对于一个初入LaTeX的人,这或许是一个较好的选择,但是对于一个足够熟悉LaTeX的人来讲,不是必须的,也是符合Linux思维。

综上所述,vim-latexvimtex都是优秀的LaTeX插件,但是前者提供了完备的功能,后者的优势功能是一些低频率使用的功能,综合平衡的话还是选择vim-latex更好一些。由于二者并不冲突,所以可以同时配置二个插件,获取各自的功能这是一个比较折中的方案,但是不太符合Linux纯净化的哲学思想,所以我还是选择了前者,在没有足够的理由前应该不会同时安装二者。

作为可用的配置,下面将二者的配置文件列出,方便大家参考:

~/.config/nvim/lua/plg/vim-latex.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /usr/bin/env lua
--
-- vim-latex.lua
-- Copyright (C) 2023 feng <feng@arch>
--
-- Distributed under terms of the MIT license.
--
-- vim-latex默认的局势键
-- F1 帮助菜单
-- F5 插入环境选择对话框,若在导言区将弹出插入宏包对话框
-- F7 插入引用选择对话框
--绑定快捷键
-- -- 测试功能
-- inoremap <buffer><silent> <C-S-F5> <C-O>:call <SID>ChangeEnvironment(input('Environment? '))<CR>
-- noremap <buffer><silent> <C-S-F5> :call <SID>ChangeEnvironment(input('Environment? '))<CR>
vim.api.nvim_create_autocmd("FileType",{
pattern = "tex",
callback = function()
-- 配置F4打开模板
vim.api.nvim_set_keymap("n", "<F4>", ":TTemplate<CR>", {noremap = true, silent = true})
-- 配置pdflatex编译,原vim-latex中使用\ll 默认 xelatex 编译
vim.api.nvim_set_keymap("n", "<F6>", [[<cmd>!pdflatex % <CR>]], {noremap = true, silent = true})
-- 配置F8编译 aux辅助文件,直接根据数据库生成文献引用, 注意使用%:t:r 截取文件名
vim.api.nvim_set_keymap("n", "<F8>", [[<cmd>!bibtex %:t:r.aux <CR>]], {noremap = true, silent = true})
-- 配置F10编译多合一文件时,以当前目录名为主文件,以节省时间
vim.api.nvim_set_keymap("n", "<F10>", [[<cmd>!xelatex $(echo $PWD|awk -F"/" '{print $NF}').tex <CR>]], {noremap = true, silent = true})
end
})
-- 开启treesitter提供的语法高亮
vim.api.nvim_create_autocmd( 'FileType', { pattern = 'tex',
callback = function(args)
vim.treesitter.start(args.buf, 'latex')
vim.bo[args.buf].syntax = 'on' -- only if additional legacy syntax is needed
end
})
-- set for vim-latex/latex-suite
vim.g['Tex_Menus'] = 0
vim.g['Tex_Flavor'] = 'latex'
vim.g['Tex_IgnoreLevel'] = 8
vim.g['Tex_GotoError'] = 0
vim.g['Tex_DefaultTargetFormat'] = 'pdf'
-- 配置默认编译引擎为 xelatex
vim.g['Tex_CompileRule_pdf'] = 'xelatex -synctex=1 -interaction=nonstopmode -file-line-error-style $*'
-- 获取桌面环境,并根据桌面环境选择默认的PDF阅读器
if os.getenv("DESKTOP_SESSION") == "plasma" then
vim.g['Tex_ViewRule_pdf'] = 'okular'
else
vim.g['Tex_ViewRule_pdf'] = 'evince'
end
-- 统一设置为轻量级的mupdf阅读器
-- vim.g['Tex_ViewRule_pdf'] = 'mupdf'
--控制统计过程中的警告信息
vim.g['Tex_IgnoredWarnings'] = {}
--
vim.g['Tex_CustomTemplateDirectory'] = "~/.latex-templates/"
~/.config/nvim/lua/plg/vimtex.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#! /usr/bin/env lua
--
-- vimtex.lua
-- Copyright (C) 2023 feng <feng@archlinux>
--
vim.g['tex_flavor'] = 'latex'
vim.g['vimtex_view_method'] = 'zathura'
vim.g['vimtex_view_general_viewer'] = 'zathura'
vim.g['vimtex_view_general_options'] = [[--unique file:@pdf\#src:@line@tex]]
vim.g['vimtex_compiler_latexmk_engines'] = {
_ = '-xelatex'
}
vim.g['vimtex_compiler_progname'] = 'nvr'
-- vim.g['vimtex_view_general_options_latexmk'] = '--unique'
-- vim.g['vimtex_view_general_options_latexmk'] = '--reuse-instance'
--
-- A few examples of disabling default VimTeX features.
vim.g['tex_comment_nospell'] = 1
vim.g['vimtex_quickfix_mode'] = 1
vim.g['vimtex_indent_enabled'] = 1 -- turn off VimTeX indentation
vim.g['vimtex_imaps_enabled'] = 1 -- disable insert mode mappings (e.g. if you use UltiSnips)
vim.g['vimtex_complete_enabled'] = 1 -- turn off completion
vim.g['vimtex_syntax_enabled'] = 1 -- disable syntax conceal
vim.g['vimtex_syntax_conceal_disable'] = 1 --avoid the startup warning
-- 使一些符号以一种更加直观的方式显示出来
vim.g['tex_conceal'] = 'abdmg'
vim.g['conceallevel'] = 1
-- 更改maplocalleader避免与vim-latex的冲突
vim.g['maplocalleader'] = ","

参考文章

  1. VimAwesome
  2. vim-latex.sourceforge
  3. 用Vim高效地编辑LaTeX文档

这是一款可以实现数学符号对齐的插件,测试后发现很实用,于是直接粘上其README.md, 如下

This is a mirror of http://www.vim.org/scripts/script.php?script_id=294

Align and AlignMaps lets you align statements on their equal signs, make comment boxes, align comments, align declarations, etc.

Note: this plugin is not a left&right margin justification tool! See vimscript#177 or vimscript#2324 for that. Note: if you have vim 7.1 or later, your vimball should unpack just fine without having to update it.

There are two basic commands provided by this package:

    AlignCtrl options sep1 sep2 sep3 ... 
    [range]Align sep1 sep2 sep3 ... 

The "sep#" are regular expressions which describe separators that delineate fields; Align will line up the separators. The range may be any Vim range, including visual-blocks. Align works on lines of the form: (ws==whitespace, sep==separator, field==text)

ws-field-ws-sep-ws-field-ws-sep-ws-field-... 
ws-field-ws-sep-ws-field-ws-sep-ws-field-... 

Note that white-space (ws) surrounding separators is ignored.

The Align package includes:

  • Align : the basic alignment command
  • AlignCtrl : provides options for the next call to :Align
  • AlignMaps : many three or four key maps which support aligning C/C++ style declarations, ()?..:.., expressions, C/C++ comments, numbers, C preprocessor definitions, tables based on tabs or spaces, and more.

In addition, AutoAlign (vimscript#884) uses the Align function to align =s as you type.

Align handles alignment on multiple separators, not just the first one, and the separators may be the same across the line or different. With AlignCtrl one may specify that separators are cyclic (re-used sequentially) or equivalent (all separators are simultaneously active).

There are several options to help with deciding what to do with initial white space. By default Align re-uses the first line's initial white space, but one may use AlignCtrl to retain or remove each line's initial white space.

The <Align.vim> and <AlignMaps.vim> files are plugins and require vim 6.1 or higher.

EXAMPLES:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
:5,10Align = 
Align on '=' signs

:'<,'>Align = + - \* /
Align on any of the five separator characters shown.
Note that visual block mode was used to fire off Align.

:AlignCtrl =lp1P1I
which means:
= all separators are equivalent
l fields will be left-justified
p1 pad one space before each separator
P1 pad one space after each separator
I preserve and apply the first line's leading white space to all
Align'd lines

:help align
Gives help for Align

ALIGNMENT CONTROL

Alignment control allows for left or right justification or centering of fields, cyclic (sequentially active) or equivalent (simultaneously active) regular expressions to specify field separators, initial white space control, optional visual-block use (ie. apply Alignment only within a block), user-specified white-space padding about separators, and multiple separators.

MANY ALIGNMENT MAPS

AlignMaps.vim provides a number of maps which make using this package easy. They typically either apply to the range 'a,. (from mark a to current line) or use the visual-selection (V, v, or ctrl-v selected):

1
2
3
4
5
\t=  : align assignments (don't count logic, like == or !=) 
\t, : align on commas
\t| : align on vertical bars (|)
\tsp : align on whitespace
\tt : align LaTeX tabular tables

AlignMaps also provides some internally complex maps for aligning C declarations, Ansi C function arguments, html tables, LaTeX tabulars, and trailing comments:

1
2
3
4
\acom : align comments 
\adec : align C declarations (one variable per line)
\afnc : align ansi-style C function input arguments
\Htd : align html tables

To see some examples of this, check out

[http://mysite.verizon.net/astronaut/vim/align.html#Examples](http://mysite.verizon.net/astronaut/vim/align.html#Examples) 

(the proportional fonts used by most browsers in showing you this page preclude showing the examples here). The help for Align and AlignCtrl also contains many examples.

ALIGNMENT ON VISUAL BLOCKS AND g,v-LIKE CONTROL

Sometimes one wants to align only a subset of text in a range, based on patterns or column extents. Align supports both types of restrictions!

Visual-block selection may be used to restrict Align to operate only 
within that visual block. 
 
AlignCtrl supports "g" and "v" patterns that restrict Align to 

operate on lines which match (or don't match, respectively) those 
patterns. 

NEW STUFF:

There's a number of new AlignCtrl options:

- allows one to skip a separator (treat it as part of a field) 
+ repeat the last lrc justification (ex. lr+ == lrrrrrr... ) 
: treat the rest of the line as a field; acts as a modifier 
  to the last lrc. 
< left-justify the separator 
> right-justify the separator 
| center the separator 

These are, except for the ":", cyclic parameters. In other words, >< is equivalent to ><><><><... . Thus separators can be of differing lengths (ex. -+ as a separator pattern can match -, --, ---, etc and the separators will be left/right/center justified as you wish).

To get automatic, as-you-type, aligning of = in the C, vimL, and other languages, check out vimscript#884 for several ftplugins (which use Align).

Alternative Aligners: Gergely Kontra's vimscript#176

Thank you for rating Align!

DISCUSSION and COMMENTS:

Please use email for bugs. Enjoy!

(alpha/beta version available at http://mysite.verizon.net/astronaut/vim/index.html#ALIGN)

CDNJS是一个JS资料库,可以直接在网页上应用它上面拥有的一些JS文件。为什么不直接引用自己下载下来的库而要引用上面的文件呢?因为引用上面的文件可以使用户浏览网站的速度更佳,可以提高用户体验。Next主题的CDNJS直接调用的https://cdnjs.cloudflare.com, 按Next主题官方说法

Particularly, if you are a Chinese blogger or most of your visits come from China, please note that the CDNJS is blocked in some parts of China, don't use it as your CDN provider.

Next主题默认检测网站根目录安装的插件,将其视为内部的插件,对于某些未检测到的插件视为第三方插件。知道这个特性后,我们首先要做的就是安装@next-theme/plugins, 这样适配Next主题的特定插件就会在托管的网站内部加载,这可以保证Next的各项功能正常工作。操作如下:

1
2
diary --ThemeUpdate
npm install @next-theme/plugins

先更新Next主题的目的是匹配最新的@next-theme/plugins, 于是可以保证主题内部插件工作良好。然而Next主题的一些部分还采用了图标,这些图标并不在@next-theme/plugins范围内,其中最重要的local-search插件也会受到影响,所以需要加载CDN网站到第三方插件。目前国内有很多 NPM 的 CDN,可以支持相关包文件的高速访问下载,其中库比较全的CDN推荐以下三个:

其中Zstatic用到了镜像回源,也就是说只要访问一次,文件就会被存储到国内的服务器上,再也不用担心缓存过期了,所以网络文章建议优先用这个,但是在本博客主题上测试效果并不好。如果您使用 cdnjs.com 只需要替换 cdnjs.cloudflare.coms4.zstatic.net 即可,如

1
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
替换成
1
<script src="https://s4.zstatic.net/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

如果您使用 unpkg.com 只需要替换 unpkg.com 为 s4.zstatic.net/npm 即可,如

1
<script src="https://unpkg.com/react@16.7.0/umd/react.production.min.js"></script>
替换成
1
<script src="https://s4.zstatic.net/npm/react@16.7.0/umd/react.production.min.js"></script>

批量替换代码:

1
2
find . -type f -exec sed -i 's#https://unpkg.com#https://s4.zstatic.net/npm#g' {} +
find . -type f -exec sed -i 's#https://cdnjs.cloudflare.com#https://s4.zstatic.net#

  • Hexo Next主题在V8.19.0版本后就支持自定义cdnjs了,所以配置了s4.zstatic.net, 测试访问速度可以。2024年01月22日发现本博客的PDF组件无法使用,于是判断是s4.zstatic.net同步的js不全导致,更换为cdn.onmicrosoft.cnmirrors.sustech.edu.cn/cdnjs后问题解决,尽管在网络上看到文章推荐使用前者,但是在博客中表现来看后二者更佳,并且南科大镜像更加快速一些,完美适配了我的Next主题。
  • 2024年09月27日, 南方科技大学的cdn镜像访问出现问题,于是为保证网站正常访问不得不修复此问题。经过研究,安装@next-theme/plugins后,可以保证PDFNext主题依赖的插件由站内加载,其他部分则由cdn镜像加载,于是多数的镜像均可以正常使用了,为确保访问的稳定重新切换为s4.zstatic.net, 经测试效果良好.

在学会使用GitLab写博客之后,一直工作良好,但是今天发现仓库越来越大,编写博客时速度也越来越慢,原因在于每次commit后git都会形成一个快照,于是除了必备的Hexo部分外这个.git文件夹也是变的越来越大,这个才是导致仓库变大的主要原因,而作为写博客来讲,我是不需要使用commit切换回某个状态的,于是决定重置一下仓库。

  1. 创建新分支

    1
    git checkout --orphan latest

    使用--orpha选择,可创建1个无任何提交历史的清洁分支。新分支可以随意命名,但不要与以前的名冲突,只是网上乱七八糟的文章都相互抄袭,使用master而己,这是github的默认命名,而gitlab的默认名就是main.

  2. 添加所有文件

    1
    2
    3
    git add . 
    or
    git add -A

  3. commit代码

    1
    git commit -m "重置仓库"

  4. 删除原来的主分支(main)

    1
    git branch -D main

  5. 将当前分支重命名为main

    1
    git branch -m main

  6. 推送代码到远程仓库

    1
    2
    git branch --set-upstream-to=origin/main main
    git push -f origin main

    注意:默认gitlab开启了main分支保护,不允许强制push, 此时需要在远程仓库项目时暂时把项目保护关闭才能推送。关闭项目保护的方法: SettingsRepositoryProtected Branches , 在强推成功后一定要重新添加分支受保护。

  7. 从远程拉取新代码(测试之用)

    1
    git pull
    如果别人pull不下来,可以执行
    1
    git pull -r

  8. 确定清除历史记录的结果

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    # 查看提交日志
    git log --pretty=oneline
    # 查看分支信息
    # 列出所有本地分支
    $ git branch
    # 列出所有远程分支
    $ git branch -r
    # 列出所有本地分支和远程分支
    # $ git branch -a

    # 查看 tag 信息
    # 查看本地标签
    git tag
    # 查看远程标签
    git ls-remote --tags

LaTeX 大型文档通常使用多文件方法用于组织项目文件,以方便快速定位、修改。一般来说,建议使用subfiles宏包来组织多文件的大型文档,简单易用。 standalone宏包则可以用来编制会议论文集,每篇文章都使用独立的导言区,以避免自定义命令冲突。

subfiles宏包

主文件

主文件与普通LaTeX差不多。只是需要引用subfiles宏包,使用subfile命令导入子文件。

main.tex 主文件
1
2
3
4
5
6
7
8
9
10
11
12
13
\documentclass{main}
\usepackage{subfiles} % 尽量置于导言区的最后
\graphicspath{{contents/images/}}

\title{文档标题}
\author{作者}
\date{}

\begin{document}
\maketitle
\subfile{contents/chp-01} % 导入第一章
\subfile{contents/chp-02} % 导入第二章
\end{document}
阅读全文 »

在使用vimnvim编译latex文件时,对于单个源文件,自然使用vim-latex插件足够应对,但是对于一个多合一文件,比如说一本书,这里会有一个主文件,然后各个章节分开来写,但是每次写一部分后都要切换到主文件编译,然后再回到当前章节文件编辑,这显然是十分低效率的。于是研究使用一键编译,在多合一文件时能够直接编译主文件,设计思路是:

  1. 建立一个文件夹,. 例如:特殊函数/特殊函数.tex

  2. 绑定'F10'映射到编译命令,使用shell命令截取文件夹的名称,也就获得了主文件的名称,进而直接编译就可以了,文件夹内的其他子文件就不用再管了。

  3. 映射设置,位于'~/.config/nvim/lua/plg/vim-latex.lua`中,相关部分设置为:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    --绑定快捷键
    vim.api.nvim_create_autocmd("FileType",{
    pattern = "tex",
    callback = function()
    -- 配置F4打开模板
    vim.api.nvim_set_keymap("n", "<F4>", ":TTemplate<CR>", {noremap = true, silent = true})
    -- 配置pdflatex编译,原vim-latex中使用\ll 默认 xelatex 编译
    vim.api.nvim_set_keymap("n", "<F6>", [[<cmd>!pdflatex % <CR>]], {noremap = true, silent = true})
    -- 配置F8编译 aux辅助文件,直接根据数据库生成文献引用, 注意使用%:t:r 截取文件名
    vim.api.nvim_set_keymap("n", "<F8>", [[<cmd>!bibtex %:t:r.aux <CR>]], {noremap = true, silent = true})
    -- 配置F10编译多合一文件时,以当前目录名为主文件,以节省时间
    vim.api.nvim_set_keymap("n", "<F10>", [[<cmd>!xelatex $(echo $PWD|awk -F"/" '{print $NF}').tex <CR>]], {noremap = true, silent = true})
    end
    })

  4. 多合一文件的结构参考

    特殊函数
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    \documentclass[a4paper,fontset = windows]{ctexbook}
    \usepackage{xeCJKfntef}
    \usepackage[svgnames]{xcolor}
    \usepackage[margin=2cm]{geometry}
    \usepackage{tikz}
    \usetikzlibrary{patterns}
    \usepackage{float}
    \usepackage{amsfonts}
    \usepackage{amssymb}
    \usepackage{mathtools}
    \usepackage{amsthm}
    \usepackage{amsmath}
    \usepackage{physics}
    \usepackage{multicol}
    \usepackage{lineno}
    %\usepackage{mathpazo}
    \usepackage[
    pdfborder=0 0 0,
    bookmarksnumbered=true
    ]{hyperref}
    \usepackage[user=teacher]{cexam}
    \usepackage{colornote}
    \usepackage[fontwarning=off]{ctrlwarning}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.18}
    %\usepackage{doc}
    %\usepackage{draftwatermark}
    %\SetWatermarkText{冯振华}
    \includeonly{
    Gamma函数,
    Reimannζ函数,
    常系数线性微分方程,
    特殊函数的微分解法,
    积分变换,
    特殊函数的积分解法,
    Whittaker,
    椭圆函数,
    不等式高级水平必备,
    线性代数,
    张量分析,
    附录,
    }
    \begin{document}
    %\title{\Huge 特殊函数新解}
    %\author{ 冯振华}
    %\date{2020年12月3日}
    %\maketitle
    \input{coverpage}
    \tableofcontents
    \include{Gamma函数}
    \include{Reimannζ函数}
    \include{常系数线性微分方程}
    \include{特殊函数的微分解法}
    \include{积分变换}
    \include{特殊函数的积分解法}
    \include{Whittaker}
    \include{椭圆函数}
    \include{不等式高级水平必备}
    \include{线性代数}
    \include{张量分析}
    \include{附录}
    \end{document}

注意:在绑定到F10的编译命令中,本来应当借助于vimscript的内置变量,但是%:h返回值是当前目录的缩写., 而我需要的是和主文件同名的文件夹名,同时也没有使用shell截取字符串的方法,因为##%都被vimscript解析成它的命令用来替换,所以直接使用了awk来截截取文件夹名,从而也获得了主文件的名称。同时注意,由于使用了主文件/主文件.tex的命名方式,在多文件latex的编辑过程中,应当遵守这个规定命名。同时键位F9已经分配给了nabla插件,用来显示公式,所以此处多合一编辑分配了最后一个键位F10

在编写vim或nvim配置文件时需要用到当前目录和文件名,所以此罗列出来:

符号 表示
% 当前完整的文件名
%:h 文件名的头部,即文件目录.例如../path/test.c就会为../path
%:t 文件名的尾部.例如../path/test.c就会为test.c
%:r 无扩展名的文件名.例如../path/test就会成为test
%:e 扩展名
%:t:r.aux 文件名.aux
各种效果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Examples, when the file name is "src/version.c", current dir
"/home/mool/vim": >
:p /home/mool/vim/src/version.c
:p:. src/version.c
:p:~ ~/vim/src/version.c
:h src
:p:h /home/mool/vim/src
:p:h:h /home/mool/vim
:t version.c
:p:t version.c
:r src/version
:p:r /home/mool/vim/src/version
:t:r version
:e c
:s?version?main? src/main.c
:s?version?main?:p /home/mool/vim/src/main.c
:p:gs?/?\\? \home\mool\vim\src\version.c

Examples, when the file name is "src/version.c.gz": >
:p /home/mool/vim/src/version.c.gz
:e gz
:e:e c.gz
:e:e:e c.gz
:e:e:r c
:r src/version.c
:r:e c
:r:r src/version
:r:r:r src/versio

近期重装了ArchLinux,但是又遇到KDE Plasma5桌面环境下无法挂载Windows所在硬盘问题,具体是什么原因造成的尚不明确,但是百度之后找到了解决方法:

1
sudo ntfsfix -d /dev/nvme0n1p6

注意:第一条命令需要加参数-d, 按好多资料没有加-d修复无效。原因参考资料:Mounting ntfs partition by ntfs3 failed

Check your dmesg for errors with ntfs3. Chances are the volume is still marked dirty, and ntfs3 will not mount a partition where that is the case without the force option. ntfsfix without any arguments will actively set the dirty bit, so that a chkdsk from Windows can do a real check/analysis. If you don't have that handy and want to clear the dirty bit despite ntfsfix not being entirely a good checking tool you can pass the -d argument to ntfsfix.

如果你一直在使用 Arch Linux 或其他基于 Arch 的发行版,如 Manjaro,那么可能会遇到 AUR。你尝试安装新软件,有人建议从 AUR 中安装它。这让你感到困惑。什么是 AUR?为什么使用它?如何使用 AUR?我将在本文中回答这些问题。

什么是 AUR?

AUR 表示 Arch 用户仓库(Arch User Repository)。它是针对基于 Arch 的 Linux 发行版用户的社区驱动的仓库。它包含名为 PKGBUILD 的包描述,它可让你使用 makepkg 从源代码编译软件包,然后通过 pacman(Arch Linux 中的软件包管理器)安装。

阅读全文 »