From e721c7428e0070d83568b67c761d34fb89c4b653 Mon Sep 17 00:00:00 2001
From: John MacFarlane <fiddlosopher@gmail.com>
Date: Sat, 21 Jan 2012 14:46:27 -0800
Subject: [PATCH] Removed `beamer` output format; added `--beamer` option.

---
 README                       | 21 +++++++++++++++------
 src/Text/Pandoc.hs           |  2 --
 src/Text/Pandoc/Templates.hs |  1 -
 src/pandoc.hs                | 33 +++++++++++++++++++++------------
 4 files changed, 36 insertions(+), 21 deletions(-)

diff --git a/README b/README
index 493fdb3d1..717f83e02 100644
--- a/README
+++ b/README
@@ -14,7 +14,7 @@ Pandoc is a [Haskell] library for converting from one markup format to
 another, and a command-line tool that uses this library. It can read
 [markdown] and (subsets of) [Textile], [reStructuredText], [HTML],
 and [LaTeX]; and it can write plain text, [markdown], [reStructuredText],
-[XHTML], [HTML 5], [LaTeX], [LaTeX beamer], [ConTeXt], [RTF], [DocBook XML],
+[XHTML], [HTML 5], [LaTeX], [ConTeXt], [RTF], [DocBook XML],
 [OpenDocument XML], [ODT], [Word docx], [GNU Texinfo], [MediaWiki markup], [EPUB],
 [Textile], [groff man] pages, [Emacs Org-Mode], [AsciiDoc], and [Slidy],
 [DZSlides], or [S5] HTML slide shows. It can also produce [PDF] output
@@ -141,8 +141,8 @@ Options
 :   Specify output format.  *FORMAT* can be `native` (native Haskell),
     `json` (JSON version of native AST), `plain` (plain text),
     `markdown` (markdown), `rst` (reStructuredText), `html` (XHTML 1),
-    `html5` (HTML 5), `latex` (LaTeX), `beamer` (LaTeX beamer), `context`
-    (ConTeXt), `man` (groff man), `mediawiki` (MediaWiki markup), `textile`
+    `html5` (HTML 5), `latex` (LaTeX), `context` (ConTeXt),
+    `man` (groff man), `mediawiki` (MediaWiki markup), `textile`
     (Textile), `org` (Emacs Org-Mode), `texinfo` (GNU Texinfo), `docbook`
     (DocBook XML), `opendocument` (OpenDocument XML), `odt` (OpenOffice text
     document), `docx` (Word docx), `epub` (EPUB book), `asciidoc` (AsciiDoc),
@@ -293,6 +293,10 @@ Options
 `--listings`
 :   Use listings package for LaTeX code blocks
 
+`--beamer`
+:   Produce LaTeX output for the `beamer` document class.
+    This has an effect only for `latex` or `pdf` output.
+
 `--section-divs`
 :   Wrap sections in `<div>` tags (or `<section>` tags in HTML5),
     and attach identifiers to the enclosing `<div>` (or `<section>`)
@@ -423,6 +427,11 @@ Options
     id="BookId">` (a randomly generated UUID). Any of these may be
     overridden by elements in the metadata file.
 
+`--latex-engine=`*pdflatex|lualatex|xelatex*
+:   Use the specified LaTeX engine when producing PDF output.
+    The default is `pdflatex`.  If the engine is not in your PATH,
+    the full path of the engine may be specified here.
+
 `-D` *FORMAT*, `--print-default-template=`*FORMAT*
 :   Print the default template for an output *FORMAT*. (See `-t`
     for a list of possible *FORMAT*s.)
@@ -587,13 +596,13 @@ depending on the output format, but include:
 `s5-url`
 :   base URL for S5 documents (defaults to `ui/default`)
 `font-size`
-:   font size (10pt, 11pt, 12pt) for LaTeX and beamer documents
+:   font size (10pt, 11pt, 12pt) for LaTeX documents
 `documentclass`
 :   document class for LaTeX documents
 `theme`
-:   theme for beamer documents
+:   theme for LaTeX beamer documents
 `colortheme`
-:   colortheme for beamer documents
+:   colortheme for LaTeX beamer documents
 
 Variables may be set at the command line using the `-V/--variable`
 option. This allows users to include custom variables in their
diff --git a/src/Text/Pandoc.hs b/src/Text/Pandoc.hs
index c505ec965..187fb98d7 100644
--- a/src/Text/Pandoc.hs
+++ b/src/Text/Pandoc.hs
@@ -188,8 +188,6 @@ writers = [("native"       , writeNative)
           ,("latex"        , writeLaTeX)
           ,("latex+lhs"    , \o ->
                              writeLaTeX o{ writerLiterateHaskell = True })
-          ,("beamer"       , \o ->
-                             writeLaTeX o{ writerBeamer = True })
           ,("context"      , writeConTeXt)
           ,("texinfo"      , writeTexinfo)
           ,("man"          , writeMan)
diff --git a/src/Text/Pandoc/Templates.hs b/src/Text/Pandoc/Templates.hs
index c3cacd809..ca2776ffc 100644
--- a/src/Text/Pandoc/Templates.hs
+++ b/src/Text/Pandoc/Templates.hs
@@ -87,7 +87,6 @@ getDefaultTemplate _ "docx"   = return $ Right ""
 getDefaultTemplate user "odt" = getDefaultTemplate user "opendocument"
 getDefaultTemplate user "pdf" = getDefaultTemplate user "latex"
 getDefaultTemplate user "epub" = getDefaultTemplate user "html"
-getDefaultTemplate user "beamer" = getDefaultTemplate user "latex"
 getDefaultTemplate user writer = do
   let format = takeWhile (/='+') writer  -- strip off "+lhs" if present
   let fname = "templates" </> "default" <.> format
diff --git a/src/pandoc.hs b/src/pandoc.hs
index bb190aeba..c1ca7afcd 100644
--- a/src/pandoc.hs
+++ b/src/pandoc.hs
@@ -129,7 +129,8 @@ data Opt = Opt
     , optCslFile           :: FilePath
     , optAbbrevsFile       :: Maybe FilePath
     , optListings          :: Bool       -- ^ Use listings package for code blocks
-    , optLaTeXProgram      :: String   -- ^ Program to use for latex -> pdf
+    , optLaTeXEngine       :: String     -- ^ Program to use for latex -> pdf
+    , optBeamer            :: Bool       -- ^ Produce latex output for beamer class
     }
 
 -- | Defaults for command-line options.
@@ -177,7 +178,8 @@ defaultOpts = Opt
     , optCslFile           = ""
     , optAbbrevsFile       = Nothing
     , optListings          = False
-    , optLaTeXProgram      = "pdflatex"
+    , optLaTeXEngine       = "pdflatex"
+    , optBeamer            = False
     }
 
 -- | A list of functions, each transforming the options data structure
@@ -374,6 +376,11 @@ options =
                   (\opt -> return opt { optListings = True }))
                  "" -- "Use listings package for LaTeX code blocks"
 
+    , Option "" ["beamer"]
+                 (NoArg
+                  (\opt -> return opt { optBeamer = True }))
+                 "" -- "Produce latex output for beamer class"
+
     , Option "" ["section-divs"]
                  (NoArg
                   (\opt -> return opt { optSectionDivs = True }))
@@ -549,13 +556,13 @@ options =
                   "FILENAME")
                  "" -- "Path of epub metadata file"
 
-    , Option "" ["latex-program"]
+    , Option "" ["latex-engine"]
                  (ReqArg
                   (\arg opt -> do
                      let b = takeBaseName arg
                      if (b == "pdflatex" || b == "lualatex" || b == "xelatex")
-                        then return opt { optLaTeXProgram = arg }
-                        else err 45 "latex-program must be pdflatex, lualatex, or xelatex.")
+                        then return opt { optLaTeXEngine = arg }
+                        else err 45 "latex-engine must be pdflatex, lualatex, or xelatex.")
                   "PROGRAM")
                  "" -- "Name of latex program to use in generating PDF"
 
@@ -786,7 +793,8 @@ main = do
               , optAbbrevsFile       = cslabbrevs
               , optCiteMethod        = citeMethod
               , optListings          = listings
-              , optLaTeXProgram      = latexProgram
+              , optLaTeXEngine       = latexEngine
+              , optBeamer            = beamer
              } = opts
 
   when dumpArgs $
@@ -816,11 +824,11 @@ main = do
 
   when (writerName' == "pdf") $ do
     -- check for latex program
-    mbLatex <- findExecutable latexProgram
+    mbLatex <- findExecutable latexEngine
     case mbLatex of
          Nothing  -> err 41 $
-           latexProgram ++ " not found. " ++
-           latexProgram ++ " is needed for pdf output."
+           latexEngine ++ " not found. " ++
+           latexEngine ++ " is needed for pdf output."
          Just _   -> return ()
 
   reader <- case (lookup readerName' readers) of
@@ -894,13 +902,13 @@ main = do
                               stateStandalone      = standalone',
                               stateCitations       = map CSL.refId refs,
                               stateSmart           = smart || writerName' `elem`
-                                                     ["latex", "context", "latex+lhs", "beamer"],
+                                                     ["latex", "context", "latex+lhs", "pdf"],
                               stateOldDashes       = oldDashes,
                               stateColumns         = columns,
                               stateStrict          = strict,
                               stateIndentedCodeClasses = codeBlockClasses,
                               stateApplyMacros     = writerName' `notElem`
-                                                     ["latex", "latex+lhs", "beamer"] }
+                                                     ["latex", "latex+lhs", "pdf"] }
 
   let writerOptions = defaultWriterOptions
                                     { writerStandalone       = standalone',
@@ -934,6 +942,7 @@ main = do
                                            slideVariant == DZSlides,
                                       writerChapters         = chapters,
                                       writerListings         = listings,
+                                      writerBeamer           = beamer,
                                       writerHighlight        = highlight,
                                       writerHighlightStyle   = highlightStyle }
 
@@ -986,7 +995,7 @@ main = do
                 | writerName' == "docx"  ->
            writeDocx referenceDocx writerOptions doc2 >>= writeBinary
                 | writerName' == "pdf"  ->
-           do res <- tex2pdf latexProgram $ writeLaTeX writerOptions doc2
+           do res <- tex2pdf latexEngine $ writeLaTeX writerOptions doc2
               case res of
                    Right pdf -> writeBinary pdf
                    Left err' -> err 43 $ toString err'