安装latex

ISO安装latex

下载https://mirrors.tuna.tsinghua.edu.cn/CTAN/systems/texlive/Images/

图片alt

图片alt


运行安装程序
图片alt

图片alt

命令行安装

sudo apt-get install texlive-full
sudo apt-get install texstudio
sudo apt-get install texlive-xetex latex-cjk-all

安装中文字体包
安装中文支持包,使用的是xeCjK,中文处理技术也有很多,xeCJK是成熟且稳定的一种

sudo apt install latex-cjk-all
sudo apt-get install texlive-lang-chinese

Latex解决表格过宽问题,自适应调整宽度

\resizebox{\linewidth}{!}{  #此处!表示根据根据宽高比进行自适应缩放
\begin{tabular}...
....
....
\end{tabular}
} # 注意加的位置在\begin{tabular}和\end{tabular}前后
print(xtable(matrix(rnorm(200), ncol = 10)), scalebox = 0.7)

latex的基本命令

宏包管理

tlmgr option repository https://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet --usermode
tlmgr init-usertree
tlmgr list --only-installed
sudo apt-get install perl-tk
tlmgr info collections
/usr/local/texlive/2021/bin/x86_64-linux/tlmgr --usermode  install biblatex-caspervector --repo https://mirrors.ustc.edu.cn/CTAN/systems/texlive/tlnet 

https://www.tug.org/texlive/doc/tlmgr.html#USER-MODE

查询帮助

texdoc ctex
texdoc lshort-zh
texdoc graphicx

导出

latex --interaction=nonstopmode --output-directory aa svg.tex
dvisvgm --no-fonts --no-styles -c2,2 -o a.svg svg.dvi

文档编写

\documentclass{article}
\usepackage{CJKutf8}
\begin{document}
\begin{CJK}{UTF8}{gkai}
  Hello latex!\\
  这是一个楷体中文测试,处理简体字。\\
\end{CJK}
\end{document}
\documentclass{article}
\usepackage{xeCJK}
\begin{document}
hello,你好
\end{document}
\RequirePackage{fontspec}

\setmainfont{Times New Roman}
\setsansfont{Myriad Pro}
\setmonofont{Courier Std}

\setCJKmainfont[BoldFont={方正小标宋_GBK}, ItalicFont={方正楷体_GBK}, BoldItalicFont={方正仿宋_GBK}]{方正书宋_GBK}
\setCJKsansfont{方正黑体_GBK}
\setCJKmonofont{方正中等线_GBK}
% 导言区全局设置
\documentclass{ctexart} % article book report letter

%\usepackage{ctex}
\usepackage{chemformula}

\title{My First Article}
\author{WANG YANG}
\date{\today}
%\usepackage{chemfig}% 化学环境
\usepackage[version=4]{mhchem}  % 引入宏包,版本请参考文档说明。

%正文区
\begin{document}
	\maketitle
	Hello Word 
	 $$你好$$
	$$ P\{\mbox{拒绝} \mid H_{0} \mbox{为真}\} = \alpha $$
	formula : $f(x)$
	 $$f(x)=3x^2$$
	 
	 
\ce{\mbox{蔗糖} + UDPG <=>T[蔗糖合成酶] UDPG + \mbox{果糖}} % 一个简单的公式
\end{document}

定义新命令

\documentclass{article}
%\newcommand{cmd}[args][default]{def}
\newcommand*{\CMD}[2][arg1]{#1 ----- #2}
%\renewcommand{\CMD}{test}
%\newenvironment{envname}[args][default]{begdef}{enddef}

\newenvironment{myabstract}[1][abstract]
{\begin{center}
		#1
\end{center}
\begin{quotation}
-----------------------
}
{\end{quotation}}

\begin{document}
	\CMD{arg2}
	\begin{myabstract}[test]
		ssss
	\end{myabstract}
\end{document}

插入图片

\usepackage{graphicx}
\usepackage{subfigure}
\begin{figure}[htbp]
	\centering
	\subfigure[pic1.]{
		\includegraphics[width=5.5cm]{miRNA_4023_vs_2558_RWP1_deg_volcano}
		%\caption{fig1}
	}
	\quad
	\subfigure[pic2.]{
		\includegraphics[width=5.5cm]{miRNA_4023_vs_2558_RWP1_deg_volcano}
	}
	\quad
	\subfigure[pic3.]{
		\includegraphics[width=5.5cm]{miRNA_4023_vs_2558_RWP1_deg_volcano}
	}
	\quad
	\subfigure[pic4.]{
		\includegraphics[width=5.5cm]{miRNA_4023_vs_2558_RWP1_deg_volcano}
	}
	\caption{ pics}
\end{figure}
\begin{figure}[H]
	\begin{minipage}[t]{0.45\linewidth}
		\centering
		\includegraphics[width=0.45\textwidth]{miRNA_4023_vs_2558_RWP1_deg_volcano}
		\caption{fig111111}
	\end{minipage}%

	\begin{minipage}[t]{0.45\linewidth}
		\centering
		\includegraphics[width=0.45\textwidth]{miRNA_4023_vs_2558_RWP1_deg_volcano}
		\caption{fig222222}
	\end{minipage}
\end{figure}

Splitting subfigures/minipage between two pages

图片alt

图片alt

参考文献

直接使用

%dddddddddddddd\cite{atticle1}

%\begin{thebibliography}{88}
%	\bibitem{atticle1}sssssssssssss
%\end{thebibliography}

bibtex

"xelatex",
"bibtex",
"xelatex",
"xelatex"
\documentclass{ctexart}
\usepackage{ctex}
\usepackage{natbib}
\bibliographystyle{plain} % plain unsrt alpha abbrv

\begin{document}
\cite{Dorrity2020}
\cite{Kulkarni2019}
\cite{Tran2020}
\nocite{*}
\bibliography{test}
\end{document}

biber

https://www.ctan.org/pkg/biblatex-caspervector

\documentclass{ctexart}


\usepackage[style=caspervector,backend=biber,utf8]{biblatex}
\addbibresource{/home/wangyang/Documents/bib/library.bib}
\begin{document}
\cite{Dorrity2020}
\parencite{Kulkarni2019}
\supercite{Tran2020}

% \nocite{*}
\printbibliography[title=参考文献]
\end{document}

latex拓展

R export latex table

library(xtable)
options(xtable.table.placement="H") # latex表格
options(xtable.caption.placement="top")
mcor<-round(cor(mtcars),2)
mcor
xtable(mcor,label = "lable",caption = "caption") |> 
  print(file="/home/wangyang/workspace/tex/mcor.tex")
rmarkdownTable <- function(df){
  cat("|",paste(names(df), collapse = "|"),"|")
  cat("\n")
  cat("|",paste(rep("---", ncol(df)), collapse = "|"),"|")
  cat("\n")
  
  for(i in 1:nrow(df)){
    cat("|",paste(df[i,], collapse = "|"),"|")
    cat("\n")
  }
  invisible(NULL)
} 

vscode配置

 "latex-workshop.view.pdf.viewer": "tab",
    "latex-workshop.latex.tools": [
        {
            // 编译工具和命令
            "name": "xelatex",
            "command": "xelatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "-pdf",
                "%DOCFILE%"
            ]
        },
        {
            "name": "pdflatex",
            "command": "pdflatex",
            "args": [
                "-synctex=1",
                "-interaction=nonstopmode",
                "-file-line-error",
                "%DOCFILE%"
            ]
        },
        {
            "name": "bibtex",
            "command": "bibtex",
            "args": [
                "%DOCFILE%"
            ]
        },{
            "name": "biber",
            "command": "biber",
            "args": [
                "%DOCFILE%"
            ]
        }
    ],"latex-workshop.latex.recipes": [
        {
            "name": "xelatex",
            "tools": [
                "xelatex"
            ],
        },
        {
            "name": "pdflatex",
            "tools": [
                "pdflatex"
            ]
        },
        {
            "name": "xe->bib->xe->xe",
            "tools": [
                "xelatex",
                "biber",
                "xelatex",
                "xelatex"
            ]
        }, {
            "name": "pdf->biber->pdf->pdf",
            "tools": [
                "xelatex",
                "biber",
                "xelatex",
                // "pdflatex"
            ]
        },
        {
            "name": "pdf->bib->pdf->pdf",
            "tools": [
                "pdflatex",
                "bibtex",
                "pdflatex",
                "pdflatex"
            ]
        }
    ],

中文处理

图片alt

图片alt

https://www.jianshu.com/p/bae90bf9e5d8

输入数学符号

\alpha表示字母α;
\theta表示字母θ;
\beta表示字母β;
\gamma表示字母γ等
Latex 化学公式
有机化学公式

\begin[H] \centering \includegraphics[width=0.5\textwidth]{{imageSyntaxPrefix}$} \caption{} \label{} \end

概念