分享

pandoc 用markdown写毕业论文 markdown转pdf,docx

 Versace 2014-12-25
  因为写论文的关系,需要排版又苦于没有一个好的office,这里说的是正版,因为还要发给老师查看的缘故。

安装pandoc

这是一个痛苦而又复杂的过程,当然也可以直接下载Pandoc

安装ghc

port安装ghc

  1. sudo port install ghc  

homebrew安装ghc
  1. brew install ghc  

编译cabal

Common Architecture for Building Applications and Libraries2
Cabal是Haskell用于构建应用程序和库的公共架构。
简单的来说它是haskell的包管理,和上面的port、brew 命令类似。

下载地址http:///cabal/

解压后
  1. ghc --make Setup.hs  
  2. ./Setup configure  
  3. ./Setup build   
  4. sudo ./Setup install  

安装cabal

安装之前我们需要更新
  1. cabal update  

安装pandoc
  1. cabal install pandoc  

添加到PATH
  1. export PATH=/Users/fdhuang/.cabal/bin:$PATH  

markdown 转doc

  1. pandoc iot.md -o iot.docx  

markdown 转pdf

这里只针对于安装了mactex

openSUSE安装pandoc

  1. zypper install pandoc  

Ubuntu安装pandoc

  1. sudo aptitude install pandoc  
当然也可以用apt-get

安装mactex

下载地址:
http://mirror./systems/mac/mactex/mactex-basic.pkg

markdown转pdf

不含中文时   
  1. pandoc doc.pandoc doc.pdf  

含有中文时的简单作法
  1. pandoc --latex-engine=xelatex iot.md -o iot.pdf -V mainfont="SimSun"  

markdown转pdf 含中文

  1. pandoc --template=template.tex --latex-engine=xelatex iot.md -o iot.pdf  

也就是我们需要一个template.tex的模板用于构建,下载地址

https://raw./tzengyuxio/pages/gh-pages/pandoc/pm-template.latex

或者可以参考这个

https://github.com/gmszone/iot-doc


详细可见下文,主要是因为tex对中文支持的缘故

  1. \documentclass[$if(fontsize)$$fontsize$,$endif$$if(lang)$$lang$,$endif$$if(papersize)$$papersize$,$endif$]{$documentclass$}  
  2. \usepackage{geometry}       % 設定邊界  
  3. \geometry{  
  4.   top=1in,  
  5.   inner=1in,  
  6.   outer=1in,  
  7.   bottom=1in,  
  8.   headheight=3ex,  
  9.   headsep=2ex  
  10. }  
  11. \usepackage[T1]{fontenc}  
  12. \usepackage{lmodern}  
  13. \usepackage{amssymb,amsmath}  
  14. \usepackage{ifxetex,ifluatex}  
  15. \usepackage{fixltx2e} % provides \textsubscript  
  16. % use upquote if available, for straight quotes in verbatim environments  
  17. \IfFileExists{upquote.sty}{\usepackage{upquote}}{}  
  18. \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex  
  19.   \usepackage[utf8]{inputenc}  
  20. $if(euro)$  
  21.   \usepackage{eurosym}  
  22. $endif$  
  23. \else % if luatex or xelatex  
  24.   \usepackage{fontspec}     % 允許設定字體  
  25.   \usepackage{xeCJK}        % 分開設置中英文字型  
  26.   \setCJKmainfont{STSong}   % 設定中文字型  
  27.   \setmainfont{Georgia}     % 設定英文字型  
  28.   \setromanfont{Georgia}    % 字型  
  29.   \setmonofont{Courier New}  
  30.   \linespread{1.2}\selectfont   % 行距  
  31.   \XeTeXlinebreaklocale "zh"    % 針對中文自動換行  
  32.   \XeTeXlinebreakskip = 0pt plus 1pt % 字與字之間加入0pt至1pt的間距,確保左右對整齊  
  33.   \parindent 0em        % 段落縮進  
  34.   \setlength{\parskip}{20pt}    % 段落之間的距離  
  35.   \ifxetex  
  36.     \usepackage{xltxtra,xunicode}  
  37.   \fi  
  38.   \defaultfontfeatures{Mapping=tex-text,Scale=MatchLowercase}  
  39.   \newcommand{\euro}{€}  
  40. $if(mainfont)$  
  41.     \setmainfont{$mainfont$}  
  42. $endif$  
  43. $if(sansfont)$  
  44.     \setsansfont{$sansfont$}  
  45. $endif$  
  46. $if(monofont)$  
  47.     \setmonofont{$monofont$}  
  48. $endif$  
  49. $if(mathfont)$  
  50.     \setmathfont{$mathfont$}  
  51. $endif$  
  52. \fi  
  53. % use microtype if available  
  54. \IfFileExists{microtype.sty}{\usepackage{microtype}}{}  
  55. $if(geometry)$  
  56. \usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry}  
  57. $endif$  
  58. $if(natbib)$  
  59. \usepackage{natbib}  
  60. \bibliographystyle{plainnat}  
  61. $endif$  
  62. $if(biblatex)$  
  63. \usepackage{biblatex}  
  64. $if(biblio-files)$  
  65. \bibliography{$biblio-files$}  
  66. $endif$  
  67. $endif$  
  68. $if(listings)$  
  69. \usepackage{listings}  
  70. $endif$  
  71. $if(lhs)$  
  72. \lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{}  
  73. $endif$  
  74. $if(highlighting-macros)$  
  75. $highlighting-macros$  
  76. $endif$  
  77. $if(verbatim-in-note)$  
  78. \usepackage{fancyvrb}  
  79. $endif$  
  80. $if(tables)$  
  81. \usepackage{longtable}  
  82. $endif$  
  83. $if(graphics)$  
  84. \usepackage{graphicx}  
  85. % We will generate all images so they have a width \maxwidth. This means  
  86. % that they will get their normal width if they fit onto the page, but  
  87. % are scaled down if they would overflow the margins.  
  88. \makeatletter  
  89. \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth  
  90. \else\Gin@nat@width\fi}  
  91. \makeatother  
  92. \let\Oldincludegraphics\includegraphics  
  93. \renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}  
  94. $endif$  
  95. \ifxetex  
  96.   \usepackage[setpagesize=false, % page size defined by xetex  
  97.               unicode=false, % unicode breaks when used with xetex  
  98.               xetex]{hyperref}  
  99. \else  
  100.   \usepackage[unicode=true]{hyperref}  
  101. \fi  
  102. \hypersetup{breaklinks=true,  
  103.             bookmarks=true,  
  104.             pdfauthor={$author-meta$},  
  105.             pdftitle={$title-meta$},  
  106.             colorlinks=true,  
  107.             urlcolor=$if(urlcolor)$$urlcolor$$else$blue$endif$,  
  108.             linkcolor=$if(linkcolor)$$linkcolor$$else$magenta$endif$,  
  109.             pdfborder={0 0 0}}  
  110. \urlstyle{same}  % don't use monospace font for urls  
  111. $if(links-as-notes)$  
  112. % Make links footnotes instead of hotlinks:  
  113. \renewcommand{\href}[2]{#2\footnote{\url{#1}}}  
  114. $endif$  
  115. $if(strikeout)$  
  116. \usepackage[normalem]{ulem}  
  117. % avoid problems with \sout in headers with hyperref:  
  118. \pdfstringdefDisableCommands{\renewcommand{\sout}{}}  
  119. $endif$  
  120. \setlength{\parindent}{0pt}  
  121. %\setlength{\parskip}{6pt plus 2pt minus 1pt}  
  122. \setlength{\emergencystretch}{3em}  % prevent overfull lines  
  123.   
  124.   
  125. \title{\huge 在OSX平台上的XeLaTeX中文測試} % 設置標題,使用巨大字體  
  126. \author{FoolEgg.com}        % 設置作者  
  127. \date{February 2013}        % 設置日期  
  128. \usepackage{titling}  
  129. \setlength{\droptitle}{-8em}    % 將標題移動至頁面的上面  
  130.   
  131.   
  132. \usepackage{fancyhdr}  
  133. \usepackage{lastpage}  
  134. \pagestyle{fancyplain}  
  135.   
  136.   
  137. $if(numbersections)$  
  138. \setcounter{secnumdepth}{5}  
  139. $else$  
  140. \setcounter{secnumdepth}{0}  
  141. $endif$  
  142. $if(verbatim-in-note)$  
  143. \VerbatimFootnotes % allows verbatim text in footnotes  
  144. $endif$  
  145. $if(lang)$  
  146. \ifxetex  
  147.   \usepackage{polyglossia}  
  148.   \setmainlanguage{$mainlang$}  
  149. \else  
  150.   \usepackage[$lang$]{babel}  
  151. \fi  
  152. $endif$  
  153. $for(header-includes)$  
  154. $header-includes$  
  155. $endfor$  
  156.   
  157.   
  158. $if(title)$  
  159. \title{$title$}  
  160. $endif$  
  161. \author{$for(author)$$author$$sep$ \and $endfor$}  
  162. \date{$date$}  
  163.   
  164.   
  165. \begin{document}  
  166. $if(title)$  
  167. \maketitle  
  168. $endif$  
  169.   
  170.   
  171. $for(include-before)$  
  172. $include-before$  
  173.   
  174.   
  175. $endfor$  
  176. $if(toc)$  
  177. {  
  178. \hypersetup{linkcolor=black}  
  179. \setcounter{tocdepth}{$toc-depth$}  
  180. \tableofcontents  
  181. }  
  182. $endif$  
  183. $body$  
  184.   
  185.   
  186. $if(natbib)$  
  187. $if(biblio-files)$  
  188. $if(biblio-title)$  
  189. $if(book-class)$  
  190. \renewcommand\bibname{$biblio-title$}  
  191. $else$  
  192. \renewcommand\refname{$biblio-title$}  
  193. $endif$  
  194. $endif$  
  195. \bibliography{$biblio-files$}  
  196.   
  197.   
  198. $endif$  
  199. $endif$  
  200. $if(biblatex)$  
  201. \printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$  
  202.   
  203.   
  204. $endif$  
  205. $for(include-after)$  
  206. $include-after$  
  207.   
  208.   
  209. $endfor$  
  210. \end{document}  

也可以在这里获取一个

pandoc template pandoc 毕业设计模板


    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多