Add fic export function

master
trémeur 2 years ago
parent ddf1ea389e
commit a1a487b450

@ -491,7 +491,8 @@ Add the =memoir= class for LaTeX export.
'("memoir" '("memoir"
"\\documentclass[9pt,b6paper]{memoir} "\\documentclass[9pt,b6paper]{memoir}
[NO-DEFAULT-PACKAGES] [NO-DEFAULT-PACKAGES]
\\input{header.tex}" \\usepackage[namechapters]{optional}
\\input{$HOME/.emacs.d/fic-export-files/header.tex} %$"
("\\chapter{%s}" . "\\chapter*{%s}") ("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}") ("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}") ("\\subsection{%s}" . "\\subsection*{%s}")

@ -1,63 +0,0 @@
(defun asal-post ()
(interactive)
(goto-char (point-min))
(while (re-search-forward "<div id=\"content\"" nil t)
(replace-match "<article id=\"content\""))
(goto-char (point-min))
(while (re-search-forward "<div id=\"outline-container-" nil t)
(replace-match "<section id=\"outline-container-"))
(goto-char (point-min))
(while (re-search-forward "</div>\n</div>" nil t)
(replace-match "</div>\n</section>"))
(goto-char (point-min))
(while (re-search-forward "<hr />\n\n<p>" nil t)
(replace-match "</section>\n<section>\n<p class=\"newthought\">"))
(goto-char (point-min))
(while (re-search-forward "<hr>\n\n<p>" nil t)
(replace-match "</section>\n<section>\n<p class=\"newthought\">"))
(goto-char (point-min))
(while (re-search-forward "<div class=\"outline-text-2\" id=\".*\">" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "<div id=\"postamble\" class=\"status\">" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "<p class=\"validation\"><a href=.*>Validate</a></p>" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "</div>" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "section-number-2\">\\([0-9]*\\)<" nil t)
(replace-match "section-number-2\">\\1\.<"))
(goto-char (point-min))
(while (re-search-forward "<p class=\"author.*</p>" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "\n\n</body>" nil t)
(replace-match "\n</article>\n</body>"))
(goto-char (point-min))
(while (re-search-forward "\\\\noindent\\\\rule{\\\\textwidth}{0.5pt}" nil t)
(replace-match "\\sephim" nil t))
(goto-char (point-min))
(while (re-search-forward "\\\\maketitle" nil t)
(replace-match "\\begin{titlingpage}\n\\titleGM\n\\end{titlingpage}" nil t))
(goto-char (point-min))
(while (re-search-forward "label{\\(.*\\)}\n\\([A-Z]\\)\\([a-z]*\\)" nil t)
(replace-match "label{\\1}\n\\\\lettrine{\\2}{\\3}"))
(goto-char (point-min))
(while (re-search-forward "label{\\(.*\\)}\n\\([A-Z]\\)\\([a-z]*\\)" nil t)
(replace-match "label{\\1}\n\\\\lettrine{“\\2}{\\3}")))
(defun asal-pre ()
(interactive)
(org-format)
(goto-char (point-min))
(while (re-search-forward "\\[fn:\\([0-9]*\\):\\(.*\\)\\]" nil t)
(replace-match "@@html:<label for=\"\\1\" class=\"margin-toggle sidenote-number\"></label><input type=\"checkbox\" id=\"\\1\" class=\"margin-toggle\"/><span class=\"sidenote\">\\2</span>@@@@latex:\\\\footnote{\\2}@@")))
(defun asal-export ()
(interactive)
(let ((org-html-head "<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\"/><link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin/><link href=\"https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,700;1,400;1,700&display=swap\" rel=\"stylesheet\"/><link rel=\"stylesheet\" href=\"https://tre.praze.net/fic/tufte.css\"/>"))
(org-html-export-to-html))
(org-latex-export-to-latex))

@ -0,0 +1,225 @@
(defun fic-ao3 ()
(interactive)
(org-format)
(let ((org-export-with-title 'nil)
(org-export-with-author 'nil)
(org-export-with-creator 'nil)
(org-export-with-date 'nil)
(org-export-with-section-numbers 'nil)
(org-export-time-stamp-file 'nil)
(org-export-with-toc 'nil)
(org-html-validation-link 'nil))
(org-html-export-to-html))
(setq oldname (concat (file-name-base) ".org"))
(setq newname (concat (file-name-base) ".html"))
(find-file-noselect newname)
(with-current-buffer newname
(goto-char (point-min))
(setq delpoint-one (search-forward "<body>\n"))
(delete-region (point-min) delpoint-one)
(goto-char (point-max))
(setq delpoint-two (search-backward "</body>"))
(delete-region delpoint-two (point-max))
(goto-char (point-min))
(while (re-search-forward "<div.*>" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "</div>" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "\n\n" nil t)
(replace-match "\n"))
(write-file newname)
(kill-ring-save (point-min) (point-max)))
(kill-buffer newname)
(with-current-buffer oldname
(delete-file newname)))
(defun fic-export ()
(interactive)
(shell-command "cp ~/.emacs.d/fic-export-files/FFXYevon.ttf .")
(setq asal (y-or-n-p "ASAL?"))
(if asal
(progn
(setq title t)
(setq multichapter t)
(setq chaptertitles nil)
(setq ffx t))
(progn
(setq title (y-or-n-p "Use the fic title in exports?"))
(setq multichapter (y-or-n-p "Multichapter?"))
(if multichapter
(setq chaptertitles (y-or-n-p "Titled chapters?")))
(setq ffx (y-or-n-p "FFX fic?"))))
(org-format)
(goto-char (point-min))
(while (re-search-forward "\\[fn:\\([0-9]*\\):\\(.*\\)\\]" nil t)
(replace-match "@@html:<label for=\"\\1\" class=\"margin-toggle sidenote-number\"></label><input type=\"checkbox\" id=\"\\1\" class=\"margin-toggle\"/><span class=\"sidenote\">\\2</span>@@@@latex:\\\\footnote{\\2}@@"))
(let ((user-full-name "ovely")
(org-html-head "<link rel=\"preconnect\" href=\"https://fonts.googleapis.com\"/><link rel=\"preconnect\" href=\"https://fonts.gstatic.com\" crossorigin/><link href=\"https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400;0,700;1,400;1,700&display=swap\" rel=\"stylesheet\"/><link rel=\"stylesheet\" href=\"https://tre.praze.net/fic/tufte.css\"/>"))
(org-html-export-to-html)
(org-latex-export-to-latex))
(save-buffer)
(setq htmlfile (concat (file-name-base) ".html"))
(find-file-noselect htmlfile)
(with-current-buffer htmlfile
(goto-char (point-min))
(while (re-search-forward "<div id=\"content\"" nil t)
(replace-match "<article id=\"content\""))
(goto-char (point-min))
(while (re-search-forward "<div id=\"outline-container-" nil t)
(replace-match "<section id=\"outline-container-"))
(goto-char (point-min))
(while (re-search-forward "</div>\n</div>" nil t)
(replace-match "</div>\n</section>"))
(goto-char (point-min))
(while (re-search-forward "<hr />\n\n<p>" nil t)
(replace-match "</section>\n<section>\n<p class=\"newthought\">"))
(goto-char (point-min))
(while (re-search-forward "<hr>\n\n<p>" nil t)
(replace-match "</section>\n<section>\n<p class=\"newthought\">"))
(goto-char (point-min))
(while (re-search-forward "<div class=\"outline-text-2\" id=\".*\">" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "<div id=\"postamble\" class=\"status\">" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "<p class=\"validation\"><a href=.*>Validate</a></p>" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "</div>" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "section-number-2\">\\([0-9]*\\)<" nil t)
(replace-match "section-number-2\">\\1\.<"))
(goto-char (point-min))
(while (re-search-forward "<p class=\"author.*</p>" nil t)
(replace-match ""))
(goto-char (point-min))
(while (re-search-forward "\n\n</body>" nil t)
(replace-match "\n</article>\n</body>"))
(if (not title)
(progn
(goto-char (point-min))
(while (re-search-forward "<h1.*" nil t)
(replace-match ""))))
(if multichapter
(if (not chaptertitles)
(progn
(goto-char (point-min))
(while (re-search-forward "<span class=\"section-number-.*</span>" nil t)
(replace-match ""))))
(progn
(goto-char (point-min))
(while (re-search-forward "<h2.*" nil t)
(replace-match ""))))
(save-buffer)
(kill-current-buffer))
(setq texfile (concat (file-name-base) ".tex"))
(find-file-noselect texfile)
(with-current-buffer texfile
(shell-command
(format "pandoc %s -o %s.epub"
(shell-quote-argument (buffer-file-name))
(shell-quote-argument (file-name-base))))
(goto-char (point-min))
(while (re-search-forward "label{\\(.*\\)}\n\\([A-Z]\\)\\([a-z]*\\)" nil t)
(replace-match "label{\\1}\n\\\\lettrine{\\2}{\\3}"))
(goto-char (point-min))
(while (re-search-forward "label{\\(.*\\)}\n\\([A-Z]\\)\\([a-z]*\\)" nil t)
(replace-match "label{\\1}\n\\\\lettrine{“\\2}{\\3}"))
(if ffx
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\noindent\\\\rule{\\\\textwidth}{0.5pt}" nil t)
(replace-match "\\sepffx" nil t)))
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\noindent\\\\rule{\\\\textwidth}{0.5pt}" nil t)
(replace-match "\\sephim" nil t))))
(if multichapter
(if title
(if asal
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\maketitle" nil t)
(replace-match "\\begin{titlingpage}\n\\titleasal\n\\end{titlingpage}" nil t)))
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\maketitle" nil t)
(replace-match "\\begin{titlingpage}\n\\titlegen\n\\end{titlingpage}" nil t))))
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\maketitle" nil t)
(replace-match ""))))
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\maketitle" nil t)
(replace-match ""))))
(if multichapter
(if (not chaptertitles)
(progn
(goto-char (point-min))
(while (re-search-forward "namechapters" nil t)
(replace-match "nonamechapters"))))
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\chapter.*" nil t)
(replace-match ""))
(if title
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\begin{document}" nil t)
(replace-match "\\\\begin{document}\n\\\\chapter\*{\\\\thetitle}"))))))
(if multichapter
(if title
(if chaptertitles
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\begin{document}" nil t)
(replace-match "\\begin{document}\n\\pagestyle{multititlechapters}" nil t)))
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\begin{document}" nil t)
(replace-match "\\begin{document}\n\\pagestyle{multititlenochapters}" nil t))))
(if chaptertitles
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\begin{document}" nil t)
(replace-match "\\begin{document}\n\\pagestyle{multinotitlechapters}" nil t)))
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\begin{document}" nil t)
(replace-match "\\begin{document}\n\\pagestyle{multinotitlenochapters}" nil t)))))
(if title
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\begin{document}" nil t)
(replace-match "\\begin{document}\n\\pagestyle{singletitle}" nil t)))
(progn
(goto-char (point-min))
(while (re-search-forward "\\\\begin{document}" nil t)
(replace-match "\\begin{document}\n\\pagestyle{plain}" nil t)))))
(goto-char (point-max))
(save-buffer)
(shell-command
(format "xelatex -interaction=batchmode %s"
(shell-quote-argument (buffer-file-name))))
(shell-command
(format "xelatex -interaction=batchmode -halt-on-error %s"
(shell-quote-argument (buffer-file-name))))
(kill-current-buffer))
(delete-file "FFXYevon.ttf")
(if (file-exists-p (concat (file-name-base) ".aux"))
(delete-file (concat (file-name-base) ".aux")))
(if (file-exists-p (concat (file-name-base) ".log"))
(delete-file (concat (file-name-base) ".log")))
(if (file-exists-p (concat (file-name-base) ".out"))
(delete-file (concat (file-name-base) ".out")))
(if (file-exists-p (concat (file-name-base) ".toc"))
(delete-file (concat (file-name-base) ".toc")))
(if (file-exists-p "texput.log")
(delete-file "texput.log"))
(delete-file texfile)
(message "Done"))

Binary file not shown.

@ -0,0 +1,39 @@
(TeX-add-style-hook
"header"
(lambda ()
(TeX-add-to-alist 'LaTeX-provided-package-options
'(("hyperref" "hidelinks") ("titlesec" "explicit")))
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "href")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperref")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperimage")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "hyperbaseurl")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "nolinkurl")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "url")
(add-to-list 'LaTeX-verbatim-macros-with-braces-local "path")
(add-to-list 'LaTeX-verbatim-macros-with-delims-local "path")
(TeX-run-style-hooks
"microtype"
"lettrine"
"mathspec"
"pifont"
"titling"
"polyglossia"
"xcolor"
"graphicx"
"hyperref"
"titlesec"
"nameref")
(TeX-add-symbols
"sephim"
"sepffx"
"currentname"
"titlegen"
"titleasal")
(LaTeX-add-polyglossia-langs
'("english" "defaultlanguage" "variant=british"))
(LaTeX-add-fontspec-newfontcmds
"yevon")
(LaTeX-add-xcolor-definecolors
"shadecolor"))
:latex)

@ -0,0 +1,136 @@
\usepackage{microtype}
\usepackage{lettrine}
\usepackage{mathspec}
\setmainfont{Linux Libertine O}
\setmathfont(Digits){TeX Gyre Pagella Math}
\setmathfont(Latin,Greek){Linux Libertine O}
\setmonofont[Scale=0.8]{Noto Sans Mono}
\setsansfont{Noto Sans}
\newfontfamily\yevon{FFXYevon.ttf}
\usepackage{pifont}
\newcommand{\sephim}{\vspace{1em}\fancybreak{\ding{98}}\vspace{1em}}
\newcommand{\sepffx}{\vspace{0.5em}\begin{center}{\yevon
A}\end{center}\vspace{0.5em}}
\usepackage{titling}
\usepackage{polyglossia}
\setdefaultlanguage[variant=british]{english}
\usepackage{xcolor}
\definecolor{shadecolor}{gray}{0.85}
\usepackage{graphicx}
\PassOptionsToPackage{hyphens}{url}\usepackage[hidelinks]{hyperref}
\hypersetup{
colorlinks,
linkcolor={red!50!black},
citecolor={green!30!black},
urlcolor={blue!80!black}
}
\makeatletter
\DeclareMathSymbol{0}{\mathalpha}{\eu@DigitsArabic@symfont}{`0}
\DeclareMathSymbol{1}{\mathalpha}{\eu@DigitsArabic@symfont}{`1}
\DeclareMathSymbol{2}{\mathalpha}{\eu@DigitsArabic@symfont}{`2}
\DeclareMathSymbol{3}{\mathalpha}{\eu@DigitsArabic@symfont}{`3}
\DeclareMathSymbol{4}{\mathalpha}{\eu@DigitsArabic@symfont}{`4}
\DeclareMathSymbol{5}{\mathalpha}{\eu@DigitsArabic@symfont}{`5}
\DeclareMathSymbol{6}{\mathalpha}{\eu@DigitsArabic@symfont}{`6}
\DeclareMathSymbol{7}{\mathalpha}{\eu@DigitsArabic@symfont}{`7}
\DeclareMathSymbol{8}{\mathalpha}{\eu@DigitsArabic@symfont}{`8}
\DeclareMathSymbol{9}{\mathalpha}{\eu@DigitsArabic@symfont}{`9}
\makeatother
\emergencystretch 3em % keeps text fully justified
\raggedbottom
\setsecnumdepth{chapter} % unnumbered sections
\opt{nonamechapters}{
\usepackage[explicit]{titlesec}
\titleformat{\chapter}[display]
{\HUGE\bfseries}{\thechapter}{0pt}{\Huge}}
\opt{namechapters}{
\chapterstyle{lyhne}
}
\usepackage{nameref}
\makeatletter
\newcommand*{\currentname}{\@currentlabelname}
\makeatother
\nouppercaseheads
\makepagestyle{multititlechapters}
\makeevenhead{multititlechapters}{\thepage}{}{\itshape\thetitle}
\makeoddhead{multititlechapters}{\itshape\currentname}{}{\thepage}
\makepagestyle{multititlenochapters}
\makeevenhead{multititlenochapters}{\thepage}{}{\itshape\thetitle}
\makeoddhead{multititlenochapters}{\itshape
Chapter~\thechapter}{}{\thepage}
\makepagestyle{multinotitlechapters}
\makeevenhead{multinotitlechapters}{\thepage}{}{\itshape\theauthor}
\makeoddhead{multinotitlechapters}{\itshape\currentname}{}{\thepage}
\makepagestyle{multinotitlenochapters}
\makeevenhead{multinotitlenochapters}{\thepage}{}{\itshape\theauthor}
\makeoddhead{multinotitlenochapters}{\itshape Chapter~\thechapter}{}{\thepage}
\makepagestyle{singletitle}
\makeevenhead{singletitle}{\thepage}{}{\itshape\theauthor}
\makeoddhead{singletitle}{\itshape\thetitle}{}{\thepage}
\settocdepth{chapter}
\bibintoc
\counterwithout{footnote}{chapter}
\newcommand*{\titlegen}{\begingroup% Scripts, T&H p 151
\centering
\vspace*{0.1\textheight}
{\Huge\bfseries\thetitle}\\[\baselineskip]
{\large\itshape by \theauthor}\\[\baselineskip]
\vfill
\rule{0.4\textwidth}{0.4pt}\\[\baselineskip]
{\large\itshape\the\year{}}\par
\vspace*{0.1\textheight}
\endgroup}
\newcommand*{\titleasal}{\begingroup
\begin{minipage}{0.05\textwidth}
\color{red}
\rule{6pt}{\textheight}
\end{minipage}
\hspace{0.05\textwidth}
\begin{minipage}{0.6\textwidth}
\vspace*{0.1\textheight}
{\Large OVELY} \\
\rule{0.9\textwidth}{1pt} \par
\vspace{3\baselineskip}
{\noindent\Huge\bfseries A SHOT} \par
\vspace{2\baselineskip}
{\noindent\Huge\bfseries AT LIFE} \par
\vspace{6\baselineskip}
{\scshape a Final Fantasy X fanfiction} \par
\vspace{0.4\baselineskip}
\rule{0.9\textwidth}{1pt} \par
\vspace{\baselineskip}
{\Large \the\year}
\end{minipage}
\hfill
\begin{minipage}{0.15\textwidth}
\vspace{3.5\baselineskip}
{\color{red}
\HUGE
{\yevon L} \\[1.15\baselineskip]
{\yevon I} \\[1.15\baselineskip]
{\yevon F} \\[1.15\baselineskip]
{\yevon E}
}\par
\end{minipage}
\endgroup}

@ -1,20 +0,0 @@
(require 'ox-latex)
(setq org-export-headline-levels 6)
(setq org-html-head-include-default-style nil)
(setq org-footnote-define-inline t)
(setq org-export-with-creator nil)
(setq org-export-with-toc nil)
(setq org-export-time-stamp-file nil)
(setq org-latex-default-class "memoir")
(setq org-latex-compiler "xelatex")
(setq org-html-validation-link nil)
(setq org-html-doctype "html5")
(add-to-list 'org-latex-classes
'("memoir"
"\\documentclass[9pt,b6paper]{memoir}
[NO-DEFAULT-PACKAGES]
\\input{header.tex}"
("\\chapter{%s}" . "\\chapter*{%s}")
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")))
Loading…
Cancel
Save