Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Algorithm numbers as hyperlinks #45

Open
sebsciarra opened this issue Jul 26, 2023 · 0 comments
Open

Algorithm numbers as hyperlinks #45

sebsciarra opened this issue Jul 26, 2023 · 0 comments

Comments

@sebsciarra
Copy link

sebsciarra commented Jul 26, 2023

Just wondering if algorithms can be references as a hyperlinks as, for example, Equations. For example, the below latex equation could be referenced throughout a document, with the number being a hyperlink to the equation.

\begin{align}
x = 1 
\label{eq:equation}
\end{align}

If I try adding something similar to an algorithm environment (whether insider the algorithm or algorithmic environments), the algorithm does not compile, and as a result, does not show up on my webpage. That is, if I remove \label{alg:grad_descent} from the code below, the pseudocode block compiles and shows up.

<pre id="eq:grad_descent" class="pseudocode"  data-line-number=true >
    \begin{algorithm}
    \caption{Gradient Descent}
    \begin{algorithmic}
     \label{alg:grad_descent}
    \REQUIRE{Function for computing loss function, $\ell_{MSE}$ (see Equation $\ref{eq:mse-matrix}$)}
    \INPUT{Initial guess for weights $\mathbf{w}^{(0)}$} 
    \PROCEDURE{gradientDescent}{$K, \epsilon, \tau$}
      \STATE{$k = 0$}
     \WHILE{$k < K$ \AND $\lVert \mathbf{w}^{(k)} - \mathbf{w}^{(k+1)} \rVert^2_2 < \epsilon$} 
     \STATE{$\mathbf{w}^{(k+1)} = \mathbf{w}^{(k)} - \tau \nabla_{\mathbf{w}}\ell_{MSE}(\mathbf{w}^{(k)})$.} 
     \STATE{$k \mathrel{+}= 1$}
      \ENDWHILE
    \ENDPROCEDURE
    \end{algorithmic}
    \end{algorithm}
</pre>

Here is how I call pseudocode.js ( I call is internally, given that I am using MathJax 4.0.0-beta3).

  <script src="https://cdn.jsdelivr.net/npm/[email protected]/tex-chtml.js"
              integrity="sha256-ljPODBK7Jf/VfUrVqec63xzZbysEmwB9Ab20TWRMQRU="
              crossorigin="anonymous">
  </script>


  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/build/pseudocode.min.css">
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/build/pseudocode.min.js"></script>
  <script src="{{ "js/pseudocode.js" | relURL }}"></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant