独立不适用于算法

独立不适用于算法

我有一系列算法,我想为它们创建独立的 pdf 文件,以便以后添加。我尝试使用独立包,但不知何故它们不兼容。这是 MWE:

\documentclass[border=1pt]{standalone}
%\documentclass{article}

\usepackage[noend]{algpseudocode}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{mathtools}


\newcommand*\Let[2]{\State #1 $\gets$ #2}
\newcommand*\Leth[2]{\State #1 $\gets$ #2}
\newcommand*\Stateh{\State}

\newcommand{\inlinecomment}[1]{{\color{gray} \it-- #1}}

\begin{document}

\begin{algorithm}[H]
  \caption{Mesh-discontinuity interaction
    \label{alg:interact}}
  \begin{algorithmic}[0]
    \Require{A mesh $\mathcal{M} := \left\{ \mathcal{N}, \mathcal{E} \right\}$ (node and element sets) and a discontinuity set $\mathcal{D}$}
    \Statex
    \Function{interact}{$\mathcal{M}, \mathcal{D}$}
      \For{$e_i \in \mathcal{E}$} 
        \For{$d_i \in \mathcal{D}$} 
          \Let{$ \mathcal{I} $}{$e_i  \cap d_i$} 
          \If{$\mathcal{I} \neq \emptyset $} 
            \Let{$\phantom{w_ k }\mathllap{\mathcal{E}}$}{$\mathcal{E} \cup \text{s(} \mathcal{I}, e_i\text{)}$}  
            \If{$\text{isC}(d_i)$}
            \Let{$\mathcal{E}$}{$\mathcal{E} \cup \text{c}(\mathcal{I}, d_i)$}  
            \EndIf
            \For {$ n_k \in \mathcal{I}$} 
              \Let{$ \mathcal{N}$}{$\mathcal{N} \bigcup \left\{n_{k}, n_{k} \right\}$} 
              \Let{$ w_k \equiv \left\{ w_{\psi}, w_{\chi} \right\} $}{$\text{w} \left( k \right) $} 
            \EndFor
          \EndIf
        \EndFor
      \EndFor
      \State \Return{$w, \mathcal{N}, \mathcal{E}$}
    \EndFunction
  \end{algorithmic}
\end{algorithm}


\end{document}

答案1

对于那些可能对解决方案感兴趣的人来说,这是我最终使用的代码:

\documentclass[preview,border=5pt]{standalone}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor} % use color
\usepackage{algpseudocode}
\usepackage{mathtools}

\newcommand*\Let[2]{\State #1 $\gets$ #2}

\begin{document}

  \begin{algorithmic}[0]
    \Require{A mesh $\mathcal{M} := \left\{ \mathcal{N}, \mathcal{E} \right\}$ (node and element sets) and a discontinuity set $\mathcal{D}$}
    \Statex
    \Function{interact}{$\mathcal{M}, \mathcal{D}$}
      \For{$e_i \in \mathcal{E}$} 
        \For{$d_i \in \mathcal{D}$} 
          \Let{$ \mathcal{I} $}{$e_i  \cap d_i$} 
          \If{$\mathcal{I} \neq \emptyset $} 
            \Let{$\phantom{w_ k }\mathllap{\mathcal{E}}$}{$\mathcal{E} \cup \text{s(} \mathcal{I}, e_i\text{)}$}  
            \If{$\text{isC}(d_i)$}
            \Let{$\mathcal{E}$}{$\mathcal{E} \cup \text{c}(\mathcal{I}, d_i)$}  
            \EndIf
            \For {$ n_k \in \mathcal{I}$} 
              \Let{$ \mathcal{N}$}{$\mathcal{N} \bigcup \left\{n_{k}, n_{k} \right\}$} 
              \Let{$ w_k \equiv \left\{ w_{\psi}, w_{\chi} \right\} $}{$\text{w} \left( k \right) $} 
            \EndFor
          \EndIf
        \EndFor
      \EndFor
      \State \Return{$w, \mathcal{N}, \mathcal{E}$}
    \EndFunction
  \end{algorithmic}
\end{document}

产生了

在此处输入图片描述

相关内容