So much I need to add, but to get something started….

Use pyenv.

Use Python 3.

Use Jupyter notebooks.

Use the Jupyter notebook kernel matlab_kernel (I think … it was a while ago and I may be mistaken), found here. I think there’s another one that’s better but only works with recent Matlab versions (I have 2015b and I think it requires 2016a or higher) and recent Python versions.

Use notebook conversion nbconvert exporter matlab_nbconvert. Install with the following.

pip3 install matlab_nbconvert

Use custom templates for converting to LaTeX and hiding all the right cells. Here’s a bash script I wrote/cobbled together that excludes cells with certain tags in a Markdown output which is then converted by Pandoc (with the extension pandoc_minted to get nice syntax highlighting) to LaTeX.

#!/bin/bash

# write template file if it doesn't exist
template_file="./kill_hidden.tpl"
if [ ! -f $template_file ]; then
/bin/cat <<EOM >$template_file
{%- extends 'markdown.tpl' -%}

{%- block any_cell -%}
{%- if 'jupyter:kill_cell' in cell.metadata.get("tags",[]) -%}
{%- else -%}
    {{ super() }}
{%- endif -%}
{%- endblock any_cell -%}

{%-block input_group scoped-%}
{%- if 'jupyter:kill_input' in cell.metadata.get("tags",[]) and cell.cell_type == 'code'-%}
{%- else -%}
    {{ super() }}
{%- endif -%}
{%-endblock input_group -%}


{%-block output_group scoped-%}
{%- if 'jupyter:kill_output' in cell.metadata.get("tags",[]) and cell.cell_type == 'code'-%}
{%- else -%}
    {{ super() }}
{%- endif -%}
{%-endblock output_group -%}
EOM
fi

filename_ext=$(basename "$1") # with extension
filename="${filename_ext%.*}" # without

# convert to markdown (could go straight to tex but want minted)
jupyter nbconvert --to markdown --template=kill_hidden.tpl "$filename".ipynb

# convert to tex with minted plugin
pandoc --filter pandoc-minted -f markdown -t latex "$filename".md -o "$filename".tex