通过使用Git管理LaTeX文档
首先
为了向指导教官展示上次修改的内容,在接受论文指导时使用了latexdiff。
latexdiff old.tex new.tex > diff.tex
这样就可以获取旧文件和新文件之间的差异。

考虑到一眼就能看出有何变化,对于指导者来说,可能觉得很方便。然而,为了比较差异,需要保存旧的TeX文件,导致文件夹里堆积了大量过去的文件,非常麻烦。因此,引入基于Git的版本管理。
git是什么
我对这个不是很理解,但是它是一种可以让多人同时进行编程等工作的服务、软件或系统,可以明确显示谁在何时进行了编辑,可以回退到之前的版本以便在出现错误或问题时进行原因追溯。
这次将通过后述的提交来进行版本管理。通常会创建远程代码库并构建多人访问环境,但这次完全是个人使用。此外,可以考虑在共同撰写论文时也非常有用,但目前并没有计划。
准备编辑
使用git时需要在命令提示符、git bash等地方输入命令。由于我对此并不完全理解,所以只需简单考虑使用它就像施展咒语一样。与其完全理解,我更希望能够熟练地使用工具。因为我自己对输入命令并不熟悉,所以我会从初学者的角度写作。
下载
首先,根据您自己的环境从Git中下载最新版本。
创建存储库
首先确定存储论文的文件夹,并将其配置为通过git进行管理。
首先使用命令将工作目录切换到存储论文的文件夹中。
cd ./username/hoge/hogehoge
创建代码库
$ git init
忽略补助文件的文件
将.gitignore文件编辑如下,设置忽略辅助文件。
(当前已在VS Code中引入了在编译后同步之前删除辅助文件的设置。)
## addition
*.docx
## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb
## Intermediate documents:
*.dvi
*.xdv
*-converted-to.*
# these rules might exclude image files for figures etc.
# *.ps
# *.eps
# *.pdf
## Generated if empty string is given at "Please type another file name for output:"
*.pdf
## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml
## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync
## Build tool directories for auxiliary files
# latexrun
latex.out/
## Auxiliary and intermediate files from other packages:
# algorithms
*.alg
*.loa
# achemso
acs-*.bib
# amsthm
*.thm
# beamer
*.nav
*.pre
*.snm
*.vrb
# changes
*.soc
# cprotect
*.cpt
# elsarticle (documentclass of Elsevier journals)
*.spl
# endnotes
*.ent
# fixme
*.lox
# feynmf/feynmp
*.mf
*.mp
*.t[1-9]
*.t[1-9][0-9]
*.tfm
#(r)(e)ledmac/(r)(e)ledpar
*.end
*.?end
*.[1-9]
*.[1-9][0-9]
*.[1-9][0-9][0-9]
*.[1-9]R
*.[1-9][0-9]R
*.[1-9][0-9][0-9]R
*.eledsec[1-9]
*.eledsec[1-9]R
*.eledsec[1-9][0-9]
*.eledsec[1-9][0-9]R
*.eledsec[1-9][0-9][0-9]
*.eledsec[1-9][0-9][0-9]R
# glossaries
*.acn
*.acr
*.glg
*.glo
*.gls
*.glsdefs
# gnuplottex
*-gnuplottex-*
# gregoriotex
*.gaux
*.gtex
# htlatex
*.4ct
*.4tc
*.idv
*.lg
*.trc
*.xref
# hyperref
*.brf
# knitr
*-concordance.tex
# TODO Comment the next line if you want to keep your tikz graphics files
*.tikz
*-tikzDictionary
# listings
*.lol
# makeidx
*.idx
*.ilg
*.ind
*.ist
# minitoc
*.maf
*.mlf
*.mlt
*.mtc[0-9]*
*.slf[0-9]*
*.slt[0-9]*
*.stc[0-9]*
# minted
_minted*
*.pyg
# morewrites
*.mw
# nomencl
*.nlg
*.nlo
*.nls
# pax
*.pax
# pdfpcnotes
*.pdfpc
# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd
# scrwfile
*.wrt
# sympy
*.sout
*.sympy
sympy-plots-for-*.tex/
# pdfcomment
*.upa
*.upb
# pythontex
*.pytxcode
pythontex-files-*/
# thmtools
*.loe
# TikZ & PGF
*.dpth
*.md5
*.auxlock
# todonotes
*.tdo
# easy-todo
*.lod
# xmpincl
*.xmpi
# xindy
*.xdy
# xypic precompiled matrices
*.xyc
# endfloat
*.ttt
*.fff
# Latexian
TSWLatexianTemp*
## Editors:
# WinEdt
*.bak
*.sav
# Texpad
.texpadtmp
# Kile
*.backup
# KBibTeX
*~[0-9]*
# auto folder when using emacs and auctex
./auto/*
*.el
# expex forward references with \gathertags
*-tags.tex
# standalone packages
*.sta
# generated if using elsarticle.cls
*.spl
执行部分
每天写作时使用的命令
在编辑文章之前先创建一个分支(当天的分支)。添加编辑后,进行add操作然后适时进行commit(相当于记录此时此刻的内容)。在当天结束时将分支合并到主分支(将分离的分支与主分支合并)。
$ git checkout -b branchname
$ git add filename.tex
$ git commit -m 'hogehoge'
$ git checkout master
$ git merge branchname
顺便说一句,您也可以同时进行添加和提交操作。
$ git commit -am "hogehoge"
生成差分文件的命令
生成差分文件。
latexdiff-vc --git -d diff -r [ブランチ名] filename.tex
--または--
latexdiff-vc --git -d diff -r [コミットの番号7桁] filename.tex
生成差分的.tex文件会存放在以diff命名的文件夹中。
可以指定要与哪个提交做差分。
比如说
4/1收到评论+进行修正。
4/2再进行额外修正。
4/3请检查。
此时我们需要的是4/1收到评论后的文件与当前文件之间的差异,而不是与4/2之间的差异,
因此我们要创建一个与4/1收到评论时的提交和当前提交之间的差异文件。
将以下内容作为用于显示过去日志和当前文件状态的命令。
$ git log
$ git status
结束
由于写得不够细致,比想象中更粗糙,所以需要适当地进行编辑。
由于每个命令都有方便的选项,所以需要适时地进行研究并追加。
新增(22/11/22)
由于日期命名分支,所以以22/11/22的形式进行命名,但是当编译时没有指定目录时,会根据斜杠自动生成文件夹。
因此,将分支名称更改为22-11-22并进行编译,将在原文件的相同位置生成”filename-diff22-11-22.tex”,以便生成易于理解的差异文件。
为了以防万一,做个记录来后期更改分支的命令。
git checkout 22/11/22
git branch -m new-branch-name
在过去的分支中跳转,然后在第二行给它取一个新的名称。
请参考
以下是两篇博客文章的链接: