ソースを参照

Initial setup for slides

Ryan C. Thompson 5 年 前
コミット
3653a59e52
3 ファイル変更119 行追加5 行削除
  1. 35 5
      Snakefile
  2. 68 0
      extra-preamble.latex
  3. 16 0
      presentation.mkdn

+ 35 - 5
Snakefile

@@ -6,6 +6,7 @@ import regex
 import urllib.parse
 import os.path
 import bibtexparser
+import mistune
 
 from collections.abc import Iterable, Mapping
 from distutils.spawn import find_executable
@@ -13,6 +14,10 @@ from fnmatch import fnmatch
 from subprocess import check_output, check_call
 from tempfile import NamedTemporaryFile
 from bibtexparser.bibdatabase import BibDatabase
+from lxml import html
+from snakemake.utils import min_version
+
+min_version('3.7.1')
 
 try:
     from os import scandir, walk
@@ -91,7 +96,8 @@ def find_lyx():
         except Exception:
             pass
     else:
-        # Fallback which will just trigger an error when run
+        # Fallback which will just trigger an error when run (we don't
+        # want to trigger an error now, while building the rules)
         return '/bin/false'
 
 LYX_PATH = find_lyx()
@@ -201,22 +207,27 @@ def tex_gfx_extensions(tex_format = 'xetex'):
     except FileNotFoundError:
         return ()
 
+def get_mkdn_included_images(fname):
+    '''Return list of all images references in a markdown file.'''
+    with open(fname) as f:
+        tree = html.fromstring(mistune.markdown(f.read()))
+    return list(map(str, tree.xpath("//img/@src")))
+
 rsync_common_args = ['-rL', '--size-only', '--delete', '--exclude', '.DS_Store', '--delete-excluded',]
 
 rule build_all:
-    input: 'thesis.pdf', 'thesis-final.pdf'
+    input: 'thesis.pdf', 'thesis-final.pdf', 'presentation.pdf'
 
 # Note: Any rule that generates an input LyX file for this rule must
 # be marked as a checkpoint. See
 # https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#data-dependent-conditional-execution
-rule lyx_to_pdf:
+rule thesis_lyx_to_pdf:
     '''Produce PDF output for a LyX file.'''
     input: lyxfile = '{basename}.lyx',
            gfx_deps = lambda wildcards: lyx_gfx_deps(wildcards.basename + '.lyx'),
            bib_deps = lambda wildcards: lyx_bib_deps(wildcards.basename + '.lyx'),
            tex_deps = lambda wildcards: lyx_input_deps(wildcards.basename + '.lyx'),
-    # This rule doesn't produce the PDFs in graphics/
-    output: pdf='{basename,(?!graphics/).*}.pdf'
+    output: pdf='{basename,thesis.*}.pdf'
     run:
         if not LYX_PATH or LYX_PATH == '/bin/false':
             raise Exception('Path to LyX  executable could not be found.')
@@ -313,3 +324,22 @@ rule R_to_html:
     input: '{dirname}/{basename}.R'
     output: '{dirname}/{basename,[^/]+}.R.html'
     shell: 'pygmentize -f html -O full -l R -o {output:q} {input:q}'
+
+rule build_presentation:
+    input:
+        extra_preamble='extra-preamble.latex',
+        mkdn_file='{basename}.mkdn',
+        images=lambda wildcards: get_mkdn_included_images('{basename}.mkdn'.format(**wildcards)),
+    output:
+        pdf='{basename,presentation.*}.pdf'
+    params:
+        theme='Warsaw'
+    shell: '''
+    pandoc \
+      -f markdown -t beamer \
+      --pdf-engine=xelatex \
+      -o {output.pdf:q} \
+      -H {input.extra_preamble:q} \
+      -V theme:{params.theme:q} \
+      {input.mkdn_file:q}
+    '''

+ 68 - 0
extra-preamble.latex

@@ -0,0 +1,68 @@
+%% Better graphics sizes
+\usepackage{graphicx}
+% Redefine \includegraphics so that, unless explicit options are
+% given, the image width will not exceed the width or the height of the page.
+% Images get their normal width if they fit onto the page, but
+% are scaled down if they would overflow the margins.
+\makeatletter
+\def\ScaleWidthIfNeeded{%
+ \ifdim\Gin@nat@width>\linewidth
+    \linewidth
+  \else
+    \Gin@nat@width
+  \fi
+}
+\def\ScaleHeightIfNeeded{%
+  \ifdim\Gin@nat@height>0.75\textheight
+    0.75\textheight
+  \else
+    \Gin@nat@width
+  \fi
+}
+\makeatother
+
+\setkeys{Gin}{width=\ScaleWidthIfNeeded,height=\ScaleHeightIfNeeded,keepaspectratio}%
+%% \usepackage{graphicx}
+%% \makeatletter
+%% \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
+%% \def\maxheight{\ifdim\Gin@nat@height>0.7\textheight\textheight\else\Gin@nat@height\fi}
+%% \makeatother
+%% % Scale images if necessary, so that they will not overflow the page
+%% % margins by default, and it is still possible to overwrite the defaults
+%% % using explicit options in \includegraphics[width, height, ...]{}
+%% \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
+
+%% Eliminate header
+\setbeamertemplate{headline}{}
+
+%% Shorten footer title
+%% TODO: CHANGE THIS
+\makeatletter
+\setbeamertemplate{footline}
+{
+  \leavevmode%
+  \hbox{%
+  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,right]{author in head/foot}%
+    \usebeamerfont{author in head/foot}Ryan C. Thompson\hspace*{1em}
+  \end{beamercolorbox}%
+  \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,left]{title in head/foot}%
+    \usebeamerfont{title in head/foot}\hspace*{1em}Analyzing ChIP-seq Promoter Coverage Landscapes
+  \end{beamercolorbox}}%
+  \vskip0pt%
+}
+\makeatother
+
+%% \makeatletter
+%% \setbeamertemplate{footline}
+%% {
+%%   \leavevmode%
+%%   \hbox{%
+%%   \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
+%%     \usebeamerfont{author in head/foot}\insertsection
+%%   \end{beamercolorbox}%
+%%   \begin{beamercolorbox}[wd=.5\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
+%%     \usebeamerfont{title in head/foot}\insertsubsection
+%%   \end{beamercolorbox}}%
+%%   \vskip0pt%
+%% }
+%% \makeatother

+ 16 - 0
presentation.mkdn

@@ -0,0 +1,16 @@
+% Title: naïve and memory CD4 T-cell activation
+% Ryan C. Thompson \
+  Su Lab \
+  The Scripps Research Institute
+% October 24, 2019
+
+# Intro
+
+## A slide
+
+This is a slide.
+
+## Another slide
+
+This is another slide.
+