在线LaTeX编写工具overleaf极大的方便了暂时需要为论文编写伪代码的需要:
Overleaf, Online LaTeX Editor
该工具只需要简单注册就可以使用。
首先进入overleaf主页,然后完成注册和登录:
接着,需要创建用于储存LaTeX的文件夹:
接着,进入到文件夹,创建.tex文件开始编写伪代码:
然后,就可以在左侧代码框内编写LaTeX语言,在右侧框可以实时展示生成的伪代码。
本示例中的LaTex代码
\def\SetClass{article}
\documentclass{\SetClass}
\usepackage[lined,boxed,commentsnumbered,mfirstuc]{algorithm2e}
% \documentclass[1000pt]{article}
\begin{document}
\IncMargin{1em}
\begin{algorithm}\SetKwInOut{Input}{Input}\SetKwInOut{Output}{Output}% 设置输入\Input{}% $$括起来表示这是一个数学表达式,会使用英文斜体表示. \\表示换行$X = n \times gene$, expression matrix for $n$ sample with $g$ genes \\% _表示下缀$X_i$ = expression matrix of sample_i \\% \delta是latex输入希腊字母δ的方式$\delta$: probability \\$f_{mlp}$: the model \\\BlankLine% 定义函数内容\SetKwFunction{MyFuns} {MyFuns}\SetKwProg{Fn}{Function}{:}{}\Fn{\MyFuns{$X$, $X_i$, $X_{func}$, $\delta$}} {setVariables($X$, $Score$) \\% 添加注释\tcp{\emph{This is an annotation}}\label{cmt} \\Train a network, $f_{\theta,0}$, using the samples from $D_L$ \\% for循环\For{$i$ in $1 : MaxIterations$}{Pseudo-label $D_U$ using $f_{\theta, i-1}$ \\$D_{selected} \leftarrow $ Select pseudo-labels using UPS \\$\tilde{D} \leftarrow D_L \bigcup D_{selected}$ \\Initiallize new network $f_{\theta, i}$ \\Train $f_{\theta, i}$ using the samples from $\tilde{D}$. \\$f_{\theta} \leftarrow f_{\theta, i}$ \\}\KwRet $f_{\theta}$}% 定义emphemph\BlankLine\BlankLine
\end{algorithm}
\DecMargin{1em}
\end{document}
对应生成的伪代码: