LaTex数学符号,公式解析与伪代码书写

LaTex常用的具有数学意义的符号:
参考链接:https://blog.csdn.net/lanchunhui/article/details/54633576

mathbb:blackboard bold,黑板粗体 
mathcal:calligraphy(美术字) 
mathrm:math roman 
mathbf:math boldface

花体\mathcal实例:

  • \mathcal D: D 常用来表示数据集
  • \mathcal L: L 常用来表示损失函数
  • \mathcal N: N 常用来表示正态分布
  • \mathcal U: U 常用来表示均匀分布

空心体\mathbb实例:
- \mathbb D:这里写图片描述

伪代码书写

参考:
https://blog.csdn.net/qq_34369618/article/details/61205638
https://blog.csdn.net/lwb102063/article/details/53046265

实例:

\documentclass{article}  
% 所用宏包
\usepackage{algorithm}  
\usepackage{algorithmicx}  
\usepackage{algpseudocode}  
\usepackage{amsmath}  

\floatname{algorithm}{Algorithm}  % 算法的头名字
\renewcommand{\algorithmicrequire}{\textbf{Input:}} % 输入格式  
\renewcommand{\algorithmicensure}{\textbf{Output:}}  % 输出格式

\begin{document}  
    \begin{algorithm}  
        \caption{The example of using LaTex}  
        \begin{algorithmic}[1] %每行显示行号  
            \Require $Array a$$n$  % 算法的输入
            \Ensure sum of $a$       % 算法的输出

            \Function {MergerSort}{$Array, left, right$}  % 函数开始
            \State $result \gets 0$  

            \If {$left < right$}  % if的开始
            \State $middle \gets (left + right) / 2$  % 书写语句

            \State $result \gets result +$ \Call{Merger}{$Array,left,middle,right$}  % 调用函数
            \EndIf    % if的结束
            \State \Return{$result$}  % 返回结果 
            \EndFunction  % 结束函数

            \State  % 为空内容可以实现空一行

            \While{$i<middle$ \textbf{and} $j<right$}  % while的开始
            \If{$Array[i]<Array[j]$}  
            \State $B[k++]\gets Array[i++]$  
            \Else  
            \State $B[k++] \gets Array[j++]$  
            \State $result \gets result + (middle - i)$  
            \EndIf  
            \EndWhile  % 结束while语句

            \For{$i = 0 \to k-1$}   % for的开始
            \State $Array[left + i] \gets B[i]$  
            \EndFor  % for的结束
        \end{algorithmic}  
    \end{algorithm}  
\end{document}  

这里写图片描述
但是对你IEEE的LaTex模板,上述的命令语句必须改为大写,且引入的宏包也不相同。上述所用宏包为algorithmicx,而IEEE模板中所用宏包为algorithmic。两者命令的差异:https://blog.csdn.net/yeyang911/article/details/41758039。 在algorithmic中没有找到与定义函数function相关的命令。

\usepackage{algorithmic}
\usepackage{algorithm}  
\begin{algorithm}  
        \caption{The example of using LaTex}  
        \begin{algorithmic}[1] %每行显示行号  
            \REQUIRE $Array a$,$n$  % 算法的输入
            \ENSURE sum of $a$       % 算法的输出

            \STATE $result \gets 0$  

            \IF {$left < right$}  % if的开始
            \STATE $middle \gets (left + right) / 2$  % 书写语句

            \STATE $result \gets result +$ %\CALL{Merger}{$Array,left,middle,right$}  % 调用函数
            \ENDIF    % if的结束
            \STATE \RETURN{$result$}  % 返回结果 


            \STATE  % 为空内容可以实现空一行

            \WHILE{$i<middle$ \textbf{and} $j<right$}
            \IF{$Array[i]<Array[j]$}  
            \STATE $B[k++]\gets Array[i++]$  
            \ELSE 
            \STATE $B[k++] \gets Array[j++]$  
            \STATE $result \gets result + (middle - i)$  
            \ENDIF  
            \ENDWHILE  % 结束while语句

            \FOR{$i = 0 \to k-1$}   % for的开始
            \STATE $Array[left + i] \gets B[i]$  
            \ENDFOR  % for的结束
        \end{algorithmic}  
    \end{algorithm}

这里写图片描述

猜你喜欢

转载自blog.csdn.net/winycg/article/details/81252207