Traditional code embedding can be done as in markdown or beamer listings. An interesting aspect is to have the code actually executed, and its output appended here.
One example of code in Python (not executed):
This is how it’s done:
\```{.python}
print("Hello World")
\```
Command pandoc --list-highlight-styles (or just eval "$(pandoc --bash-completion)" to enable bash completion) will display options: pygments, tango, espresso, zenburn, kate, monochrome, breezedark, haddock
You can visually compare them here: https://www.garrickadenbuie.com/blog/pandoc-syntax-highlighting-examples
An interesting project for active code execution is codebraid for: Python 3.5+, Julia, Rust, R, Bash, JavaScript, and SageMath.
fenced_code_blocks and backtick_code_blocks enable code highlight on pandoc.
fenced_code_attributes can add more attributes to them.
See Manual: https://pandoc.org/MANUAL.html#fenced-code-blocks
pandoc --list-highlight-languages will list languages (a lot!)
To have code executed, you will need the plugin pandoc-source-exec from panflute pack (install as easy as python3 -m pip install pandoc-source-exec). On Pandoc, we can use .exec property (also hide=true and .hide). An specific command can be given, such as: cmd='codes/run_python2.sh'.
This approach is nice because it integrates nicely with markdown-preview-enhanced on Atom, where you can see results on real time.
\```{.python .exec cmd='codes/run_python3.sh'}
...
\```
Expected output is:
Hello
World2
Output:
\```{.python .exec cmd='codes/run_python2.sh'
hide=true .hide output_label=''}
print 'Hello'
\```
This is one of the most interesting approaches, just load script codes/example.py and execute it:
\```{.python .exec cmd='codes/run_python3.sh' args="codes/example.py"
hide=true .hide output_label=''}
\```
File example.py contains:
This is where we wanted to arrive on codes/example.cpp:
\```{.cpp .exec cmd='codes/run_cpp.sh' args="codes/example.cpp"
hide=true .hide output_label=''}
\```
File example.cpp contains:
LaTeX requires installation of pdf2svg for both markdown-preview-enhanced plugin and run_latex.sh.
\```{.latex .exec .hide hide=true cmd='codes/run_latex.sh'
void=true args="figs/pseudo1.svg" output_label=''}
\documentclass{standalone}
\usepackage[ruled,vlined,linesnumbered]{algorithm2e}
\begin{document}
\pagestyle{empty}
\begin{algorithm}[H]
\caption{Test Algo}
\end{algorithm}
\end{document}
\```
For markdown-preview-enhanced, we can see Ace Editor (also on revealjs):