Currently, when I want to add some algorithm's pseudocode to my LaTeX export, I have to manually write LaTeX:

** Pixel-Flipping: A Technique to Assess Faithfulness
- Pixel-flipping is a quantitative, empirical method to evaluate the faithfulness of explanations.
- It involves iteratively removing input features based on their importance and observing the impact on model predictions.
  - The resulting curves are called /Deletion Curves/.

#+BEGIN_SRC latex


\STATE $pfcurve = []$
\FOR{$p$ in $argsort(-R)$}

\STATE $x \leftarrow x - \{x_p\}$ (remove pixel $p$ from the image)
\STATE $pfcurve.append(f(x))$

\RETURN $pfcurve$

Is there a way I can just write the pseudocode in an org-babel source block (e.g., in Python), and it gets converted to a LaTeX algorithm block automatically?

  • Did you look at setting the :results to latex? Does that do what you want?
    – Melioratus
    Commented Dec 14, 2023 at 22:16

1 Answer 1


Be sure you have the line #+LaTeX_HEADER: \usepackage{algorithm2e} at the beginning of your .org file and then remove the lines #+BEGIN_SRC latex and #+END_SRC from your algorithm snippet. Then exporting to LaTeX/pdf will give you this: enter image description here

  • The snippet I provided in the question is LaTeX already. I want to write in a Python-like language and export as LaTeX. I guess it's not possible.
    – HappyFace
    Commented Dec 18, 2023 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.