{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Generate PDFs and Clean\n\nIn this example, we generate PDFs in one location from tex files in possibly\nvarious other locations, and clean.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Author: Fan Wang (fanwangecon.github.io)\nimport pyfan.util.pdf.pdfgen as pyfan_pdfgen\nimport pprint\nimport matplotlib.pyplot as plt\nimport textwrap\nimport json"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Generate PDF for one specific file and clean afterwards\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# spt_loc = 'C:/Users/fan/Documents/Dropbox (UH-ECON)/repos/Tex4Econ/_other/equation/'\nspt_loc = 'G:/Dropbox (UH-ECON)/repos/Tex4Econ/_other/equation/'\nspt_loc_output = 'C:/Users/fan/Documents/'\nspn_file = 'cases.tex'\nspn_pdf_exe = 'C:/texlive/2020/bin/win32/pdflatex.exe'\ndc_tex_pdf_a = pyfan_pdfgen.ff_pdf_gen_clean(ls_spt_srh=[spt_loc], spt_out=spt_loc_output,\n                                             spn_pdf_exe=spn_pdf_exe, ls_st_contain=[spn_file],\n                                             bl_clean=True)\nprint(dc_tex_pdf_a)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Generate PDF from all tex files in all subfolders of a main folder, output PDF store in one location\n\n1. spt_loc_search_root: Tex Search folder\n2. spt_loc_output: only consider files with this in name\n3. st_search_string: include in one of the element in list\n4. ls_st_ignore: ignore files with this in name\n5. PDF Destination Folder: same root path earlier folder to store possibly\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# spt_loc_search_root = 'C:/Users/fan/Documents/Dropbox (UH-ECON)/repos/Tex4Econ/_other/'\nspt_loc_search_root = 'G:/Dropbox (UH-ECON)/repos/Tex4Econ/_other/'\nspt_loc_output = 'C:/Users/fan/Documents/'\nst_search_string = ['fs_', 'cases']\nls_st_ignore = ['tikz', 'pandoc']\nspn_pdf_exe = 'C:/texlive/2020/bin/win32/pdflatex.exe'\ndc_tex_pdf_b = pyfan_pdfgen.ff_pdf_gen_clean(ls_spt_srh=[spt_loc_search_root], spt_out=spt_loc_output,\n                                             spn_pdf_exe=spn_pdf_exe,\n                                             ls_st_contain=st_search_string, ls_st_ignore=ls_st_ignore,\n                                             bl_recursive=True, bl_clean=True)\nprint(dc_tex_pdf_b)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## perl latexpand example\n\nuse latexpand\nconda activate wk_perl\ncd \"C:/Users/fan/Documents/Dropbox (UH-ECON)/repos/HgtOptiAlloDraft/zmain/\"\nperl \"C:/Users/fan/.conda/envs/wk_perl/latexpand/latexpand\" draft_main_s1.tex > draft_main_s1_flat.tex\nperl \"C:/ProgramData/Anaconda3/envs/wk_perl/latexpand/latexpand\" draft_main_s1.tex > draft_main_s1_flat.tex\npandoc --bibliography=C:/Users/fan/HgtOptiAlloDraft/_bib/zoteroref.bib -o draft_main_s1_flat.docx draft_main_s1_flat.tex\n\ncd \"C:/Users/fan/Documents/Dropbox (UH-ECON)/repos/HgtOptiAlloDraft/beamer/\"\nperl \"C:/Users/fan/.conda/envs/wk_perl/latexpand/latexpand\" present.tex > present_flat.tex\nperl \"C:/ProgramData/Anaconda3/envs/wk_perl/latexpand/latexpand\" present.tex > present_flat.tex\n\npandoc --bibliography=C:/Users/fan/HgtOptiAlloDraft/_bib/zoteroref.bib -o present_flat.docx present_flat.tex\n\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Plot String as Figure\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "# Dict of String to String\nstr_dc_records = 'One Tex to Root PDF:'.upper() + '\\n' + \\\n                 textwrap.fill(json.dumps(dc_tex_pdf_a), width=70) + '\\n' + \\\n                 'Recursive Search Tex to PDF Folder:'.upper() + '\\n' + \\\n                 textwrap.fill(json.dumps(dc_tex_pdf_b), width=70)\n# Start Plot\nfig, ax = plt.subplots()\n\n# Text Plot\nax.text(0.5, 0.5, str_dc_records,\n        horizontalalignment='center',\n        verticalalignment='center',\n        fontsize=14, color='black',\n        transform=ax.transAxes)\n\n# Labeling\nax.set_axis_off()\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.5"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}