PK!$Dmdc/__init__.py__version__ = "0.0.1" PK!].5 mdc/mdc.pyimport argparse import atexit import importlib.resources from os.path import basename, splitext import shutil import subprocess import sys from tempfile import NamedTemporaryFile, TemporaryDirectory from mdc import __version__ as mdc_version import mdc.templates __all__ = ["build_pandoc_cmd", "run_compile"] DEFAULT_FROM = "markdown-markdown_in_html_blocks-native_divs" AVAILABLE_TEMPLATES = [ splitext(basename(f))[0] for f in importlib.resources.contents(mdc.templates) if f.endswith(".tex") ] DEFAULT_TEMPLATE = "simple" DEFAULT_BIBTYPE = "natbib" DEFAULT_META = [ "figPrefix=Figure", "eqnPrefix=Equation", "tblPrefix=Table", "lstPrefix=List", "secPrefix=Section", ] DEFAULT_PANDOC = "pandoc" DEFAULT_LATEXMK = "latexmk" DEFAULT_CROSSREF = "pandoc-crossref" DEFAULT_IMG_EXT = "pdf" DEFAULT_VERBOSE = False def build_pandoc_cmd( input_file, from_=DEFAULT_FROM, template=DEFAULT_TEMPLATE, bibliography=None, bib_type=DEFAULT_BIBTYPE, crossref=DEFAULT_CROSSREF, include=None, meta=DEFAULT_META, pandoc=DEFAULT_PANDOC, ): """Build required pandoc command from given arguments.""" cmd = [pandoc] cmd.append(f"--from={from_}") cmd.append("--to=latex") if template in AVAILABLE_TEMPLATES: template_context = importlib.resources.path( mdc.templates, f"{template}.tex" ) template = template_context.__enter__() atexit.register( lambda c: c.__exit__(None, None, None), template_context ) cmd.append(f"--template={template}") if bibliography is not None: cmd.append(f"--bibliography={bibliography}") cmd.append(f"--{bib_type}") if crossref is not None: cmd.append(f"--filter={crossref}") if include: for f in include: cmd.append(f"--include-before-body={f}") if meta: for m in meta: cmd.append(f"--metadata={m}") cmd.append(f"--default-image-extension={DEFAULT_IMG_EXT}") cmd.append(input_file) return cmd def run_compile( pandoc_cmd, output_file=None, latexmk=DEFAULT_LATEXMK, verbose=DEFAULT_VERBOSE, ): """Run pandoc command to generate tex/pdf output.""" if output_file is None: subprocess.run(pandoc_cmd).check_returncode() elif output_file.endswith(".tex"): pandoc_cmd.append(f"--output={output_file}") subprocess.run(pandoc_cmd).check_returncode() elif output_file.endswith(".pdf"): # Generate tex, then compile with latexmk with NamedTemporaryFile(dir="") as temp_file: pandoc_cmd.append(f"--output={temp_file.name}") subprocess.run(pandoc_cmd).check_returncode() with TemporaryDirectory() as temp_dir: latexmk_cmd = [ latexmk, "-pdflua", f"-output-directory={temp_dir}", f"{temp_file.name}", ] if not verbose: latexmk_cmd.append("-quiet") subprocess.run(latexmk_cmd).check_returncode() # Copy generated output file tf_only_name = basename(temp_file.name) shutil.copyfile( f"{temp_dir}/{tf_only_name}.pdf", f"{output_file}" ) else: raise ValueError("output file extension must be .tex/.pdf") def main(): """Entry point.""" def _meta_arg(string): """Argument type for passing meta variables.""" if "=" not in string: raise argparse.ArgumentTypeError( "meta var should be passed as " "`key=val`" ) k, v = string.split("=") return f"{k}:{v}" arg_parser = argparse.ArgumentParser() arg_parser.add_argument("input_file", type=argparse.FileType("r")) arg_parser.add_argument( "-V", "--version", action="version", version=f"%(prog)s {mdc_version}" ) arg_parser.add_argument( "-v", "--verbose", action="store_true", help="make latexmk verbose" ) arg_parser.add_argument( "-o", "--output-file", type=str, default=None, help="write output to this file (default stdout)", ) arg_parser.add_argument( "-f", "--from", type=str, dest="from_", metavar="FROM", default=DEFAULT_FROM, help=f"pandoc input format (default {DEFAULT_FROM})", ) template_parser = arg_parser.add_mutually_exclusive_group(required=False) template_parser.add_argument( "-t", "--builtin-template", type=str, dest="template", choices=AVAILABLE_TEMPLATES, help=f"use one of the built-in templates (default {DEFAULT_TEMPLATE})", ) template_parser.add_argument( "-T", "--custom-template", type=str, dest="template", metavar="CUSTOM_TEMPLATE", help="use a custom template", ) arg_parser.set_defaults(template=DEFAULT_TEMPLATE) arg_parser.add_argument( "-b", "--bibliography", type=argparse.FileType("r"), default=None, help="bibliography argument for pandoc", ) arg_parser.add_argument( "-B", "--bib-type", type=str, choices=["natbib", "biblatex"], default=DEFAULT_BIBTYPE, help=f"bibliography type sent to pandoc (default {DEFAULT_BIBTYPE})", ) arg_parser.add_argument( "-i", "--include", type=argparse.FileType("r"), nargs="*", help="files to include before body", ) arg_parser.add_argument( "-m", "--meta", type=_meta_arg, nargs="*", default=DEFAULT_META, help="additional meta variables to pass to pandoc", ) arg_parser.add_argument( "--pandoc", type=str, default=DEFAULT_PANDOC, help=f"path to pandoc executable (default {DEFAULT_PANDOC})", ) arg_parser.add_argument( "--latexmk", type=str, default=DEFAULT_LATEXMK, help=f"path to latexmk executable (default {DEFAULT_LATEXMK})", ) arg_parser.add_argument( "--crossref", type=str, default=DEFAULT_CROSSREF, help=f"path to crossref executable (default {DEFAULT_CROSSREF})", ) args = arg_parser.parse_args() try: pandoc_cmd = build_pandoc_cmd( args.input_file.name, args.from_, args.template, args.bibliography.name, args.bib_type, args.crossref, [i.name for i in args.include], args.meta, args.pandoc, ) run_compile(pandoc_cmd, args.output_file, args.latexmk, args.verbose) except ValueError as e: print(f"ERROR: {e}", file=sys.stderr) return 1 except subprocess.CalledProcessError as e: print(f"ERROR: {e.cmd[0]} failed with return code {e.returncode}") return e.returncode PK!mdc/templates/__init__.pyPK!?OOmdc/templates/note.tex\documentclass[letterpaper]{article} \usepackage[hmargin=1.5in,tmargin=1in,bmargin=1.5in]{geometry} \usepackage[T1]{fontenc} \usepackage[babel=true,protrusion=true,expansion=true]{microtype} \usepackage[american]{babel} \usepackage{cfr-lm} \usepackage[no-math]{fontspec} \usepackage{nowidow} \usepackage{parskip} \usepackage[unicode=true,hidelinks]{hyperref} \usepackage{fancyhdr} \usepackage{titlesec} \usepackage{graphicx} \usepackage{subcaption} \usepackage{dblfloatfix} \usepackage{xcolor} \usepackage{tikz} \usepackage{booktabs} \usepackage{longtable} \usepackage{footnote} \usepackage{acronym} \usepackage{relsize} \usepackage{upquote} \usepackage{fancyvrb} % Pandoc tightlist \providecommand{\tightlist}{% \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} % Fix tables \makesavenoteenv{longtable} % Place floats at the top of float-only pages \makeatletter \setlength{\@fptop}{0pt} \setlength{\@fpbot}{0pt plus 1fil} \makeatother % Set defaults for figure, table placement \makeatletter \def\fps@figure{!tb} \def\fps@table{!tb} \makeatother % Disable page numbers \pagenumbering{gobble} % Configure acronyms \renewcommand*{\acsfont}[1]{\textsc{\textsmaller{#1}}} $for(include-before)$$include-before$$endfor$ \title{$title$} \author{$for(author)$$author.name$$sep$\quad $endfor$} \date{} \begin{document} \maketitle $body$ \end{document} PK!@bmdc/templates/simple.tex\documentclass[letterpaper,twocolumn]{article} \usepackage[hmargin=46pt,tmargin=1in,bmargin=1.5in,footskip=0.75in]{geometry} \usepackage[T1]{fontenc} \usepackage[babel=true,protrusion=true,expansion=true]{microtype} \usepackage[american]{babel} \usepackage{cfr-lm} \usepackage{nowidow} \usepackage[unicode=true,hidelinks]{hyperref} \usepackage{fancyhdr} \usepackage[absolute]{textpos} \usepackage{titlesec} \usepackage[square,numbers,super,sort&compress]{natbib} \usepackage{graphicx} \usepackage{subcaption} \usepackage{dblfloatfix} \usepackage{xcolor} \usepackage{tikz} \usepackage{booktabs} \usepackage{longtable} \usepackage{footnote} \usepackage{acronym} \usepackage{relsize} \usepackage{upquote} \usepackage{fancyvrb} \usepackage{mathtools} \usepackage{amssymb} \usepackage{amsthm} \usepackage{mleftright} \usepackage{bm} \usepackage{algpseudocode} \usepackage{algorithmicx} % Put year in citet \newcommand*{\nolink}[1]{{\protect\NoHyper#1\protect\endNoHyper}} \renewcommand{\citet}[1]{\nolink{\citeauthor{#1} (\citeyear{#1})}\citep{#1}} % Pandoc tightlist \providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} % Fix tables \makesavenoteenv{longtable} % Place floats at the top of float-only pages \makeatletter \setlength{\@fptop}{0pt} \setlength{\@fpbot}{0pt plus 1fil} \makeatother % Set defaults for figure, table placement \makeatletter \def\fps@figure{!tb} \def\fps@table{!tb} \makeatother % Configure acronyms \renewcommand*{\acsfont}[1]{\textsc{\textsmaller{#1}}} % Use mleftright \renewcommand\left\mleft \renewcommand\right\mright % Automatically use \left and \right with parentheses \makeatletter \def\resetMathstrut@{% \setbox\z@\hbox{% \mathchardef\@tempa\mathcode`\[\relax \mathchardef\@tempc\mathcode`\]\relax \def\@tempb##1"##2##3{\the\textfont"##3\char"}% \expandafter\@tempb\meaning\@tempa \relax }% \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@} \makeatother \begingroup \catcode`(\active \xdef({\left\string(} \catcode`)\active \xdef){\right\string)} \endgroup \mathcode`(="8000 \mathcode`)="8000 % Configure headings \titleformat{\section}[hang]{\raggedright\normalfont\Large}{\thesection}{3\wordsep}{} \titleformat{\subsection}[hang]{\raggedright\normalfont\large}{\thesubsection}{3\wordsep}{} \titleformat{\subsubsection}[hang]{\raggedright\normalfont\normalsize\itshape}{\thesubsubsection}{4\wordsep}{} \titleformat{\paragraph}[runin]{\normalfont\normalsize\scshape}{}{4\wordsep}{} % Set column separation \setlength{\columnsep}{1.6em} % Configure page no. \pagestyle{fancy} \fancyhf{} \renewcommand{\headrulewidth}{0pt} \fancyfoot[R]{\scriptsize\thepage} $for(include-before)$$include-before$$endfor$ \title{% \vspace{-5ex}% \begin{minipage}{\textwidth}% \begin{flushleft}% {\normalfont\Huge $title$}% \end{flushleft}% \end{minipage}% \vspace{-2ex}% } \author{% \begin{minipage}{\textwidth}% \begin{flushleft}% \hspace{-0.5em}% {% \normalfont\large\scshape% $for(author)$$author.name$\textsuperscript{$author.affiliation.id$$if(author.equalcontrib)$$if(skipequal)$$else$,*$endif$$endif$}$sep$\quad $endfor$% }% \end{flushleft}% \end{minipage}% \vspace{4ex}% } \date{} \begin{document} % Configure basic typography \nowidow[2] \parindent=2.5em \lefthyphenmin=2 \righthyphenmin=3 \maketitle \thispagestyle{fancy} \textblockorigin{0in}{11in} \setlength{\TPHorizModule}{1pt} \setlength{\TPVertModule}{1in} \begin{textblock}{400}(46,-0.9) \parindent=0pt \normalfont\scriptsize\raggedright \hrule \hrule \vspace{1.5ex} $if(skipequal)$$else$\textsuperscript{*}Equal contribution.$endif$ $for(institute)$\textsuperscript{$institute.id$}$institute.name$.$endfor$ Email:~$for(author)$\texttt{$author.email$}$sep$, $endfor$. \end{textblock} $if(abstract)$ \section*{Abstract} $abstract$ $endif$ $body$ $if(bibliography)$ \footnotesize \bibliographystyle{humannat} \bibliography{$bibliography$} $endif$ \end{document} PK!jeSmdc/templates/standalone.tex\documentclass[preview,varwidth=100in]{standalone} \usepackage[T1]{fontenc} \usepackage[babel=true,protrusion=true,expansion=true]{microtype} \usepackage[american]{babel} \usepackage{cfr-lm} \usepackage[unicode=true,hidelinks]{hyperref} \usepackage{xcolor} \usepackage{tikz} \usepackage{booktabs} \usepackage{longtable} \usepackage{acronym} \usepackage{relsize} \usepackage{mathtools} \usepackage{amssymb} \usepackage{mleftright} \usepackage{bm} \usepackage{algpseudocode} \usepackage{subcaption} \usepackage{pgf} % Use mleftright \renewcommand\left\mleft \renewcommand\right\mright % Automatically use \left and \right with parentheses \makeatletter \def\resetMathstrut@{% \setbox\z@\hbox{% \mathchardef\@tempa\mathcode`\[\relax \mathchardef\@tempc\mathcode`\]\relax \def\@tempb##1"##2##3{\the\textfont"##3\char"}% \expandafter\@tempb\meaning\@tempa \relax }% \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@} \makeatother \begingroup \catcode`(\active \xdef({\left\string(} \catcode`)\active \xdef){\right\string)} \endgroup \mathcode`(="8000 \mathcode`)="8000 % Configure acronyms \renewcommand*{\acsfont}[1]{\textsc{\textsmaller{#1}}} $for(include-before)$$include-before$$endfor$ \begin{document} $body$ \end{document} PK!R5mdc/templates/stylish.tex\documentclass[letterpaper,twocolumn]{article} \usepackage[hmargin=0.75in,vmargin=0.75in,footskip=0.5in]{geometry} \usepackage[T1]{fontenc} \usepackage[no-math]{fontspec} \usepackage[babel=true,protrusion=true,expansion=true]{microtype} \usepackage[american]{babel} \usepackage{cfr-lm} \usepackage{nowidow} \usepackage[unicode=true,hidelinks]{hyperref} \usepackage{fancyhdr} \usepackage{sectsty} \usepackage[square,numbers,super,sort&compress]{natbib} \usepackage{graphicx} \usepackage{caption} \usepackage{subcaption} \usepackage{dblfloatfix} \usepackage{xcolor} \usepackage{tikz} \usepackage{booktabs} \usepackage{longtable} \usepackage{footnote} \usepackage{acronym} \usepackage{relsize} \usepackage{upquote} \usepackage{fancyvrb} \usepackage{etoolbox} \usepackage{mathtools} \usepackage{amssymb} \usepackage{amsthm} \usepackage{amsopn} \usepackage{mleftright} \usepackage{bm} \usepackage{algpseudocode} \usepackage{algorithmicx} % Footnote without marker \newcommand\blfootnote[1]{% \begingroup \renewcommand\thefootnote{}\footnote{\raggedright \hspace{-20pt} #1}% \addtocounter{footnote}{-1}% \endgroup } % Put year in citet \newcommand*{\nolink}[1]{{\protect\NoHyper#1\protect\endNoHyper}} \renewcommand{\citet}[1]{\nolink{\citeauthor{#1} (\citeyear{#1})}\citep{#1}} % Pandoc tightlist \providecommand{\tightlist}{\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} % Fix tables \makesavenoteenv{longtable} % Place floats at the top of float-only pages \makeatletter \setlength{\@fptop}{0pt} \setlength{\@fpbot}{0pt plus 1fil} \makeatother % Set defaults for figure, table placement \makeatletter \def\fps@figure{!tb} \def\fps@table{!tb} \makeatother % Use mleftright \renewcommand\left\mleft \renewcommand\right\mright % Automatically use \left and \right with parentheses \makeatletter \def\resetMathstrut@{% \setbox\z@\hbox{% \mathchardef\@tempa\mathcode`\[\relax \mathchardef\@tempc\mathcode`\]\relax \def\@tempb##1"##2##3{\the\textfont"##3\char"}% \expandafter\@tempb\meaning\@tempa \relax }% \ht\Mathstrutbox@\ht\z@ \dp\Mathstrutbox@\dp\z@} \makeatother \begingroup \catcode`(\active \xdef({\left\string(} \catcode`)\active \xdef){\right\string)} \endgroup \mathcode`(="8000 \mathcode`)="8000 % Configure acronyms \renewcommand*{\acsfont}[1]{\textsc{\textsmaller{#1}}} % Configure (sub(sub))section fonts \sectionfont{\raggedright\normalfont\fontspec{futura_medium.ttf}[Path=\string~/.latex/fonts/]\fontsize{15}{0}\selectfont} \subsectionfont{\raggedright\normalfont\fontspec{futura_book.ttf}[Path=\string~/.latex/fonts/]\fontsize{13}{0}\selectfont} \subsubsectionfont{\raggedright\normalfont\fontspec{futura_book.ttf}[Path=\string~/.latex/fonts/]\fontsize{9}{0}\selectfont\MakeUppercase} % Configure (sub(sub))section numbers \renewcommand*{\thesection}{\arabic{section}.} \renewcommand*{\thesubsection}{\arabic{section}.\arabic{subsection}} \renewcommand*{\thesubsubsection}{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}} % Configure captions \captionsetup{justification=raggedright,singlelinecheck=true} \renewcommand{\captionfont}{\fontspec{futura_light.ttf}[Path=\string~/.latex/fonts/]} \renewcommand{\captionlabelfont}{\fontspec{futura_medium.ttf}[Path=\string~/.latex/fonts/]} % Set column separation \setlength{\columnsep}{0.3in} % Configure page no. \pagestyle{fancy} \fancyhf{} \renewcommand{\headrulewidth}{0pt} \fancyfoot[R]{\scriptsize{\thepage}} $for(include-before)$$include-before$$endfor$ \title{% \vspace{-3ex}% \begin{minipage}{\textwidth}% \begin{flushleft}% {\fontspec{futura_medium.ttf}[Path=\string~/.latex/fonts/]\fontsize{20}{0}\selectfont $title$}% \end{flushleft}% \end{minipage}% \vspace{-1ex}% } \author{% \begin{minipage}{\textwidth}% \begin{flushleft}% \hspace{-0.5em}% {% \fontspec{futura_book.ttf}[Path=\string~/.latex/fonts/]\fontsize{12}{0}\selectfont% $for(author)$$author.name$\textsuperscript{$author.affiliation.id$$if(author.equalcontrib)$$if(skipequal)$$else$,*$endif$$endif$}$sep$\quad $endfor$% }% \end{flushleft}% \end{minipage}% } \date{\vspace{-3ex}} % Configure basic typography \fussy \pretolerance 400 \emergencystretch 2em \begin{document} \maketitle \thispagestyle{fancy} \blfootnote{% {% \scriptsize\fontspec{futura_light.ttf}[Path=\string~/.latex/fonts/]% $if(skipequal)$$else$\textsuperscript{*}Equal contribution.$endif$% $for(institute)$\mbox{\textsuperscript{$institute.id$}$institute.name$.}\enspace$endfor$% Email:~$for(author)$\mbox{\texttt{$author.email$}}$sep$, $endfor$.% }% } $if(abstract)$ \hrule height 1pt \vspace{0.5em} {\small\bfseries $abstract$} \vspace{0.5em} \hrule height 1pt $endif$ $body$ $if(bibliography)$ \footnotesize \setlength{\bibsep}{0pt plus 0.3ex} \bibliographystyle{humannat} \bibliography{$bibliography$} $endif$ \end{document} PK!H3I88#$)shinymdc-0.0.1.dist-info/entry_points.txtN+I/N.,()MIb= MPK!Hu)GTUshinymdc-0.0.1.dist-info/WHEEL HM K-*ϳR03rOK-J,/R(O-)$qzd&Y)r$UV&UrPK!H_>y !shinymdc-0.0.1.dist-info/METADATAn0 vZ˖C54U|Iǟ/> F*^0&흄{,JHvmj'7/֪8Hzo<m8zlO{!Uf}Ү\q{_"{uD!ɪj5u{XAVFXnŢG _G9^UH8MYYG#y`},֨^#+  K(36AIG^QfnKY:B`jk`ӑ|ߛ!Db[zRcFe`\۳cMQQ͐؃l01MۨKդb냮sbGhҘb^IXcIī[TlG۶ 2.~PK!HofOshinymdc-0.0.1.dist-info/RECORDuI@{p0veQ)l.YتhO?fÛGi+ʦ$Qf 1 -Ĝs4k攄z,'P,RWÎ`Nz*eϷBroDHsXY=QK uuL2$ UJttXm- :;-؏bqMKɦ] x$gm}f5@A6;B 823gslzMC9z8r:*;fF`}Mm OM.u, 8ENA Ar4SKAg{-7"6wy{4y~eEr H2xEOfbHKL貹 sԵeCL :wd2]!kXG냹>\m=~a/'JU(u^ǩӞnqU!]mVQ8(rP^!> ȞrZ;٣]Q\&=(Qb~mNQoPK!$Dmdc/__init__.pyPK!].5 Cmdc/mdc.pyPK!mdc/templates/__init__.pyPK!?OOImdc/templates/note.texPK!@b!mdc/templates/simple.texPK!jeS1mdc/templates/standalone.texPK!R56mdc/templates/stylish.texPK!H3I88#$).Jshinymdc-0.0.1.dist-info/entry_points.txtPK!Hu)GTUJshinymdc-0.0.1.dist-info/WHEELPK!H_>y !(Kshinymdc-0.0.1.dist-info/METADATAPK!HofOMshinymdc-0.0.1.dist-info/RECORDPK `O