From 9a432746fc2122c89226e7faf5f528cc6d09f391 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Fri, 20 May 2022 16:28:35 +0200 Subject: [PATCH 1/7] chore(pdf): add initial test frame --- src/Handler/Admin/Test.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Handler/Admin/Test.hs b/src/Handler/Admin/Test.hs index 26a3dfbb5..d4b8aec7f 100644 --- a/src/Handler/Admin/Test.hs +++ b/src/Handler/Admin/Test.hs @@ -264,3 +264,19 @@ postAdminTestR = do |] i18n $ MsgPrintDebugForStupid "DebugForStupid" + + + + +getPDFTestR :: Handler TypedContent +getPDFTestR = do + let + writer = error "todo" + writeropts = error "todo" + doc = error "todo" + doc <- liftIO makePDF "pdflatex" writer writeropts doc + case doc of + Left bs -> + return $ TypedContent typeOctet $ toContent bs + Right bs -> + return $ TypedContent typeOctet $ toContent bs \ No newline at end of file From 62e1694b6e0c29c44db6549fe8ad5925ea726dad Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Mon, 23 May 2022 16:41:03 +0200 Subject: [PATCH 2/7] chore(pdf): add initial hello-world demo --- routes | 1 + src/Foundation/Navigation.hs | 1 + src/Handler/Admin/Test.hs | 31 ++++++++++++++++---------- templates/i18n/admin-test/en-eu.hamlet | 5 +++++ 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/routes b/routes index bec9e194d..1a496001e 100644 --- a/routes +++ b/routes @@ -55,6 +55,7 @@ !/users/add AdminUserAddR GET POST /admin AdminR GET /admin/test AdminTestR GET POST +/admin/test/pdf AdminTestPdfR GET /admin/errMsg AdminErrMsgR GET POST /admin/tokens AdminTokensR GET POST /admin/crontab AdminCrontabR GET diff --git a/src/Foundation/Navigation.hs b/src/Foundation/Navigation.hs index 6cf128d4f..11cca667f 100644 --- a/src/Foundation/Navigation.hs +++ b/src/Foundation/Navigation.hs @@ -100,6 +100,7 @@ breadcrumb AdminFunctionaryInviteR = i18nCrumb MsgBreadcrumbFunctionaryInvite No breadcrumb AdminR = i18nCrumb MsgAdminHeading Nothing breadcrumb AdminTestR = i18nCrumb MsgMenuAdminTest $ Just AdminR +breadcrumb AdminTestPdfR = i18nCrumb MsgMenuAdminTest $ Just AdminTestR breadcrumb AdminErrMsgR = i18nCrumb MsgMenuAdminErrMsg $ Just AdminR breadcrumb AdminTokensR = i18nCrumb MsgMenuAdminTokens $ Just AdminR breadcrumb AdminCrontabR = i18nCrumb MsgBreadcrumbAdminCrontab $ Just AdminR diff --git a/src/Handler/Admin/Test.hs b/src/Handler/Admin/Test.hs index d4b8aec7f..6fa490349 100644 --- a/src/Handler/Admin/Test.hs +++ b/src/Handler/Admin/Test.hs @@ -1,6 +1,7 @@ module Handler.Admin.Test ( getAdminTestR , postAdminTestR + , getAdminTestPdfR ) where import Import @@ -13,6 +14,9 @@ import qualified Data.Text as Text import qualified Data.Set as Set import qualified Data.Map as Map +import qualified Text.Pandoc as P +import qualified Text.Pandoc.PDF as P + import Handler.Admin.Test.Download (testDownload) @@ -268,15 +272,18 @@ postAdminTestR = do -getPDFTestR :: Handler TypedContent -getPDFTestR = do - let - writer = error "todo" - writeropts = error "todo" - doc = error "todo" - doc <- liftIO makePDF "pdflatex" writer writeropts doc - case doc of - Left bs -> - return $ TypedContent typeOctet $ toContent bs - Right bs -> - return $ TypedContent typeOctet $ toContent bs \ No newline at end of file +getAdminTestPdfR :: Handler TypedContent +getAdminTestPdfR = do + content <- liftIO . P.runIO $ do + let + md = "# Hello \n\n This is some Text." :: Text + texopts = [] + writeropts = def + doc <- P.readMarkdown def md + res <- P.makePDF "pdflatex" texopts P.writeLaTeX writeropts doc + case res of + Right bs -> return bs + Left err -> return err + case content of + Right bs -> return $ TypedContent typeOctet $ toContent bs + Left err -> return $ toTypedContent $ tshow err \ No newline at end of file diff --git a/templates/i18n/admin-test/en-eu.hamlet b/templates/i18n/admin-test/en-eu.hamlet index ebfbf1124..0c4b856b0 100644 --- a/templates/i18n/admin-test/en-eu.hamlet +++ b/templates/i18n/admin-test/en-eu.hamlet @@ -65,3 +65,8 @@
  • ^{modal "Email-Test" (Right emailWidget')}
  • Some icons: ^{isVisible False} ^{hasComment True} + +
    +

    Download a generated PDF + Here is a + Download-Link \ No newline at end of file From c5e8a38cd72331b0236ae0d4b933850c5539312e Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Mon, 23 May 2022 18:20:59 +0200 Subject: [PATCH 3/7] chore(pdf): send PDF with proper file download mechanics --- src/Handler/Admin/Test.hs | 15 +++++++++++---- src/Handler/Utils/Download.hs | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/Handler/Admin/Test.hs b/src/Handler/Admin/Test.hs index 6fa490349..e24d7d305 100644 --- a/src/Handler/Admin/Test.hs +++ b/src/Handler/Admin/Test.hs @@ -10,6 +10,7 @@ import Jobs import Data.Char (isDigit) import qualified Data.Text as Text +import qualified Data.ByteString.Lazy as L import qualified Data.Set as Set import qualified Data.Map as Map @@ -274,16 +275,22 @@ postAdminTestR = do getAdminTestPdfR :: Handler TypedContent getAdminTestPdfR = do + -- let typePDF = "application/pdf" :: ContentType + -- typePDF = Settings.Mime.mimeLookup "pdfdemo.pdf" content <- liftIO . P.runIO $ do - let - md = "# Hello \n\n This is some Text." :: Text + tmpl <- P.compileDefaultTemplate "latex" + let + md = "# Hello \n\n This is some *more* Text." :: Text texopts = [] - writeropts = def + writeropts = def { P.writerTemplate = Just tmpl } doc <- P.readMarkdown def md res <- P.makePDF "pdflatex" texopts P.writeLaTeX writeropts doc case res of Right bs -> return bs Left err -> return err case content of - Right bs -> return $ TypedContent typeOctet $ toContent bs + Right bs -> do + -- sendResponse (typePDF, toContent bs) -- works too + now <- liftIO getCurrentTime + sendByteStringAsFile "demoPDF.pdf" (L.toStrict bs) now Left err -> return $ toTypedContent $ tshow err \ No newline at end of file diff --git a/src/Handler/Utils/Download.hs b/src/Handler/Utils/Download.hs index 28d723bb8..5de16efe5 100644 --- a/src/Handler/Utils/Download.hs +++ b/src/Handler/Utils/Download.hs @@ -1,5 +1,6 @@ module Handler.Utils.Download ( sendThisFile + , sendByteStringAsFile , sendFileReference , serveOneFile , serveSomeFiles @@ -156,6 +157,19 @@ sendThisFile File{..} = do fileContent' .| C.map toFlushBuilder | otherwise -> sendResponseStatus noContent204 () +sendByteStringAsFile :: ( YesodAuthPersist UniWorX + , AuthEntity UniWorX ~ User + , AuthId UniWorX ~ UserId + , YesodPersistRunner UniWorX + , MonadCrypto (HandlerFor UniWorX), MonadCryptoKey (HandlerFor UniWorX) ~ CryptoIDKey + ) => FilePath -> ByteString -> UTCTime -> HandlerFor UniWorX TypedContent +sendByteStringAsFile fileTitle content fileModified = + sendThisFile File{..} + where + fileContent + | null content = Nothing + | otherwise = Just $ yield content + sendFileReference :: forall file a. ( HasFileReference file , BearerAuthSite UniWorX From e3aa6aede0fa4bf49e9058c49df590d9a79e495f Mon Sep 17 00:00:00 2001 From: Sarah Vaupel Date: Thu, 26 May 2022 15:10:05 +0200 Subject: [PATCH 4/7] chore(shell.nix): add texlive basic scheme --- shell.nix | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index cb2e37213..7b085f90e 100644 --- a/shell.nix +++ b/shell.nix @@ -70,5 +70,7 @@ let ''; in pkgs.mkShell { name = "uni2work"; - nativeBuildInputs = [develop inDevelop killallUni2work diffRunning] ++ (with pkgs; [ nodejs-14_x postgresql_12 openldap google-chrome exiftool memcached minio minio-client gup skopeo ]) ++ (with pkgs.haskellPackages; [ stack yesod-bin hlint cabal-install weeder profiteur ]); + nativeBuildInputs = [develop inDevelop killallUni2work diffRunning] + ++ (with pkgs; [ nodejs-14_x postgresql_12 openldap google-chrome exiftool memcached minio minio-client gup skopeo texlive.combined.scheme-basic ]) + ++ (with pkgs.haskellPackages; [ stack yesod-bin hlint cabal-install weeder profiteur ]); } From 33df8e6fdc106f6666ebd4b8dec02651eeca8750 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Tue, 31 May 2022 18:03:46 +0200 Subject: [PATCH 5/7] chore(pdf): pdf generation demo working --- routes | 4 ++-- src/Handler/Admin/Test.hs | 20 +++++++++---------- templates/i18n/admin-test/de-de-formal.hamlet | 5 +++++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/routes b/routes index 1a496001e..7bb7d7520 100644 --- a/routes +++ b/routes @@ -54,8 +54,8 @@ !/users/functionary-invite AdminFunctionaryInviteR GET POST !/users/add AdminUserAddR GET POST /admin AdminR GET -/admin/test AdminTestR GET POST -/admin/test/pdf AdminTestPdfR GET +/admin/test AdminTestR GET POST +/admin/test/pdf AdminTestPdfR GET /admin/errMsg AdminErrMsgR GET POST /admin/tokens AdminTokensR GET POST /admin/crontab AdminCrontabR GET diff --git a/src/Handler/Admin/Test.hs b/src/Handler/Admin/Test.hs index e24d7d305..636f3d598 100644 --- a/src/Handler/Admin/Test.hs +++ b/src/Handler/Admin/Test.hs @@ -15,8 +15,9 @@ import qualified Data.ByteString.Lazy as L import qualified Data.Set as Set import qualified Data.Map as Map -import qualified Text.Pandoc as P -import qualified Text.Pandoc.PDF as P +import qualified Text.Pandoc as P +import qualified Text.Pandoc.PDF as P +-- import qualified Text.Pandoc.Builder as P import Handler.Admin.Test.Download (testDownload) @@ -275,7 +276,7 @@ postAdminTestR = do getAdminTestPdfR :: Handler TypedContent getAdminTestPdfR = do - -- let typePDF = "application/pdf" :: ContentType + let -- typePDF = "application/pdf" :: ContentType -- typePDF = Settings.Mime.mimeLookup "pdfdemo.pdf" content <- liftIO . P.runIO $ do tmpl <- P.compileDefaultTemplate "latex" @@ -284,13 +285,12 @@ getAdminTestPdfR = do texopts = [] writeropts = def { P.writerTemplate = Just tmpl } doc <- P.readMarkdown def md - res <- P.makePDF "pdflatex" texopts P.writeLaTeX writeropts doc - case res of - Right bs -> return bs - Left err -> return err + P.makePDF "pdflatex" texopts P.writeLaTeX writeropts doc case content of - Right bs -> do - -- sendResponse (typePDF, toContent bs) -- works too + Right (Right bs) -> do + liftIO $ L.writeFile "generated.pdf" bs now <- liftIO getCurrentTime sendByteStringAsFile "demoPDF.pdf" (L.toStrict bs) now - Left err -> return $ toTypedContent $ tshow err \ No newline at end of file + -- sendResponse (typePDF, toContent bs) + Right (Left err) -> sendResponseStatus internalServerError500 $ tshow err + Left err -> sendResponseStatus internalServerError500 $ P.renderError err \ No newline at end of file diff --git a/templates/i18n/admin-test/de-de-formal.hamlet b/templates/i18n/admin-test/de-de-formal.hamlet index 0b81a7844..49a1a0a8d 100644 --- a/templates/i18n/admin-test/de-de-formal.hamlet +++ b/templates/i18n/admin-test/de-de-formal.hamlet @@ -64,3 +64,8 @@
  • ^{modal "Email-Test" (Right emailWidget')}
  • Some icons: ^{isVisible False} ^{hasComment True} + +
    +

    Download a generated PDF + Here is a + Download-Link \ No newline at end of file From 6848758ee4d3bd7be4f1acfd3a54803dee77956b Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Fri, 3 Jun 2022 11:20:12 +0200 Subject: [PATCH 6/7] chore(pdf): add latex template --- templates/generic_template.latex | 534 +++++++++++++++++++++++++++++++ 1 file changed, 534 insertions(+) create mode 100644 templates/generic_template.latex diff --git a/templates/generic_template.latex b/templates/generic_template.latex new file mode 100644 index 000000000..3874813c7 --- /dev/null +++ b/templates/generic_template.latex @@ -0,0 +1,534 @@ +% Options for packages loaded elsewhere +\PassOptionsToPackage{unicode$for(hyperrefoptions)$,$hyperrefoptions$$endfor$}{hyperref} +\PassOptionsToPackage{hyphens}{url} +$if(colorlinks)$ +\PassOptionsToPackage{dvipsnames,svgnames,x11names}{xcolor} +$endif$ +$if(CJKmainfont)$ +\PassOptionsToPackage{space}{xeCJK} +$endif$ +% +\documentclass[ +$if(fontsize)$ + $fontsize$, +$endif$ +$if(papersize)$ + $papersize$paper, +$endif$ +$if(beamer)$ + ignorenonframetext, +$if(handout)$ + handout, +$endif$ +$if(aspectratio)$ + aspectratio=$aspectratio$, +$endif$ +$endif$ +$for(classoption)$ + $classoption$$sep$, +$endfor$ +]{$documentclass$} +$if(beamer)$ +$if(background-image)$ +\usebackgroundtemplate{% + \includegraphics[width=\paperwidth]{$background-image$}% +} +$endif$ +\usepackage{pgfpages} +\setbeamertemplate{caption}[numbered] +\setbeamertemplate{caption label separator}{: } +\setbeamercolor{caption name}{fg=normal text.fg} +\beamertemplatenavigationsymbols$if(navigation)$$navigation$$else$empty$endif$ +$for(beameroption)$ +\setbeameroption{$beameroption$} +$endfor$ +% Prevent slide breaks in the middle of a paragraph +\widowpenalties 1 10000 +\raggedbottom +$if(section-titles)$ +\setbeamertemplate{part page}{ + \centering + \begin{beamercolorbox}[sep=16pt,center]{part title} + \usebeamerfont{part title}\insertpart\par + \end{beamercolorbox} +} +\setbeamertemplate{section page}{ + \centering + \begin{beamercolorbox}[sep=12pt,center]{part title} + \usebeamerfont{section title}\insertsection\par + \end{beamercolorbox} +} +\setbeamertemplate{subsection page}{ + \centering + \begin{beamercolorbox}[sep=8pt,center]{part title} + \usebeamerfont{subsection title}\insertsubsection\par + \end{beamercolorbox} +} +\AtBeginPart{ + \frame{\partpage} +} +\AtBeginSection{ + \ifbibliography + \else + \frame{\sectionpage} + \fi +} +\AtBeginSubsection{ + \frame{\subsectionpage} +} +$endif$ +$endif$ +$if(beamerarticle)$ +\usepackage{beamerarticle} % needs to be loaded first +$endif$ +\usepackage{amsmath,amssymb} +$if(fontfamily)$ +\usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$} +$else$ +\usepackage{lmodern} +$endif$ +$if(linestretch)$ +\usepackage{setspace} +$endif$ +\usepackage{iftex} +\ifPDFTeX + \usepackage[$if(fontenc)$$fontenc$$else$T1$endif$]{fontenc} + \usepackage[utf8]{inputenc} + \usepackage{textcomp} % provide euro and other symbols +\else % if luatex or xetex +$if(mathspec)$ + \ifXeTeX + \usepackage{mathspec} + \else + \usepackage{unicode-math} + \fi +$else$ + \usepackage{unicode-math} +$endif$ + \defaultfontfeatures{Scale=MatchLowercase} + \defaultfontfeatures[\rmfamily]{Ligatures=TeX,Scale=1} +$if(mainfont)$ + \setmainfont[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$]{$mainfont$} +$endif$ +$if(sansfont)$ + \setsansfont[$for(sansfontoptions)$$sansfontoptions$$sep$,$endfor$]{$sansfont$} +$endif$ +$if(monofont)$ + \setmonofont[$for(monofontoptions)$$monofontoptions$$sep$,$endfor$]{$monofont$} +$endif$ +$for(fontfamilies)$ + \newfontfamily{$fontfamilies.name$}[$for(fontfamilies.options)$$fontfamilies.options$$sep$,$endfor$]{$fontfamilies.font$} +$endfor$ +$if(mathfont)$ +$if(mathspec)$ + \ifXeTeX + \setmathfont(Digits,Latin,Greek)[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$} + \else + \setmathfont[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$} + \fi +$else$ + \setmathfont[$for(mathfontoptions)$$mathfontoptions$$sep$,$endfor$]{$mathfont$} +$endif$ +$endif$ +$if(CJKmainfont)$ + \ifXeTeX + \usepackage{xeCJK} + \setCJKmainfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmainfont$} + \fi +$endif$ +$if(luatexjapresetoptions)$ + \ifLuaTeX + \usepackage[$for(luatexjapresetoptions)$$luatexjapresetoptions$$sep$,$endfor$]{luatexja-preset} + \fi +$endif$ +$if(CJKmainfont)$ + \ifLuaTeX + \usepackage[$for(luatexjafontspecoptions)$$luatexjafontspecoptions$$sep$,$endfor$]{luatexja-fontspec} + \setmainjfont[$for(CJKoptions)$$CJKoptions$$sep$,$endfor$]{$CJKmainfont$} + \fi +$endif$ +\fi +$if(zero-width-non-joiner)$ +%% Support for zero-width non-joiner characters. +\makeatletter +\def\zerowidthnonjoiner{% + % Prevent ligatures and adjust kerning, but still support hyphenating. + \texorpdfstring{% + \textormath{\nobreak\discretionary{-}{}{\kern.03em}% + \ifvmode\else\nobreak\hskip\z@skip\fi}{}% + }{}% +} +\makeatother +\ifPDFTeX + \DeclareUnicodeCharacter{200C}{\zerowidthnonjoiner} +\else + \catcode`^^^^200c=\active + \protected\def ^^^^200c{\zerowidthnonjoiner} +\fi +%% End of ZWNJ support +$endif$ +$if(beamer)$ +$if(theme)$ +\usetheme[$for(themeoptions)$$themeoptions$$sep$,$endfor$]{$theme$} +$endif$ +$if(colortheme)$ +\usecolortheme{$colortheme$} +$endif$ +$if(fonttheme)$ +\usefonttheme{$fonttheme$} +$endif$ +$if(mainfont)$ +\usefonttheme{serif} % use mainfont rather than sansfont for slide text +$endif$ +$if(innertheme)$ +\useinnertheme{$innertheme$} +$endif$ +$if(outertheme)$ +\useoutertheme{$outertheme$} +$endif$ +$endif$ +% Use upquote if available, for straight quotes in verbatim environments +\IfFileExists{upquote.sty}{\usepackage{upquote}}{} +\IfFileExists{microtype.sty}{% use microtype if available + \usepackage[$for(microtypeoptions)$$microtypeoptions$$sep$,$endfor$]{microtype} + \UseMicrotypeSet[protrusion]{basicmath} % disable protrusion for tt fonts +}{} +$if(indent)$ +$else$ +\makeatletter +\@ifundefined{KOMAClassName}{% if non-KOMA class + \IfFileExists{parskip.sty}{% + \usepackage{parskip} + }{% else + \setlength{\parindent}{0pt} + \setlength{\parskip}{6pt plus 2pt minus 1pt}} +}{% if KOMA class + \KOMAoptions{parskip=half}} +\makeatother +$endif$ +$if(verbatim-in-note)$ +\usepackage{fancyvrb} +$endif$ +\usepackage{xcolor} +\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available +\IfFileExists{bookmark.sty}{\usepackage{bookmark}}{\usepackage{hyperref}} +\hypersetup{ +$if(title-meta)$ + pdftitle={$title-meta$}, +$endif$ +$if(author-meta)$ + pdfauthor={$author-meta$}, +$endif$ +$if(lang)$ + pdflang={$lang$}, +$endif$ +$if(subject)$ + pdfsubject={$subject$}, +$endif$ +$if(keywords)$ + pdfkeywords={$for(keywords)$$keywords$$sep$, $endfor$}, +$endif$ +$if(colorlinks)$ + colorlinks=true, + linkcolor={$if(linkcolor)$$linkcolor$$else$Maroon$endif$}, + filecolor={$if(filecolor)$$filecolor$$else$Maroon$endif$}, + citecolor={$if(citecolor)$$citecolor$$else$Blue$endif$}, + urlcolor={$if(urlcolor)$$urlcolor$$else$Blue$endif$}, +$else$ + hidelinks, +$endif$ + pdfcreator={LaTeX via pandoc}} +\urlstyle{same} % disable monospaced font for URLs +$if(verbatim-in-note)$ +\VerbatimFootnotes % allow verbatim text in footnotes +$endif$ +$if(geometry)$ +$if(beamer)$ +\geometry{$for(geometry)$$geometry$$sep$,$endfor$} +$else$ +\usepackage[$for(geometry)$$geometry$$sep$,$endfor$]{geometry} +$endif$ +$endif$ +$if(beamer)$ +\newif\ifbibliography +$endif$ +$if(listings)$ +\usepackage{listings} +\newcommand{\passthrough}[1]{#1} +\lstset{defaultdialect=[5.3]Lua} +\lstset{defaultdialect=[x86masm]Assembler} +$endif$ +$if(lhs)$ +\lstnewenvironment{code}{\lstset{language=Haskell,basicstyle=\small\ttfamily}}{} +$endif$ +$if(highlighting-macros)$ +$highlighting-macros$ +$endif$ +$if(tables)$ +\usepackage{longtable,booktabs,array} +$if(multirow)$ +\usepackage{multirow} +$endif$ +\usepackage{calc} % for calculating minipage widths +$if(beamer)$ +\usepackage{caption} +% Make caption package work with longtable +\makeatletter +\def\fnum@table{\tablename~\thetable} +\makeatother +$else$ +% Correct order of tables after \paragraph or \subparagraph +\usepackage{etoolbox} +\makeatletter +\patchcmd\longtable{\par}{\if@noskipsec\mbox{}\fi\par}{}{} +\makeatother +% Allow footnotes in longtable head/foot +\IfFileExists{footnotehyper.sty}{\usepackage{footnotehyper}}{\usepackage{footnote}} +\makesavenoteenv{longtable} +$endif$ +$endif$ +$if(graphics)$ +\usepackage{graphicx} +\makeatletter +\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} +\def\maxheight{\ifdim\Gin@nat@height>\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} +% Set default figure placement to htbp +\makeatletter +\def\fps@figure{htbp} +\makeatother +$endif$ +$if(links-as-notes)$ +% Make links footnotes instead of hotlinks: +\DeclareRobustCommand{\href}[2]{#2\footnote{\url{#1}}} +$endif$ +$if(strikeout)$ +$-- also used for underline +\usepackage[normalem]{ulem} +% Avoid problems with \sout in headers with hyperref +\pdfstringdefDisableCommands{\renewcommand{\sout}{}} +$endif$ +\setlength{\emergencystretch}{3em} % prevent overfull lines +\providecommand{\tightlist}{% + \setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}} +$if(numbersections)$ +\setcounter{secnumdepth}{$if(secnumdepth)$$secnumdepth$$else$5$endif$} +$else$ +\setcounter{secnumdepth}{-\maxdimen} % remove section numbering +$endif$ +$if(beamer)$ +$else$ +$if(block-headings)$ +% Make \paragraph and \subparagraph free-standing +\ifx\paragraph\undefined\else + \let\oldparagraph\paragraph + \renewcommand{\paragraph}[1]{\oldparagraph{#1}\mbox{}} +\fi +\ifx\subparagraph\undefined\else + \let\oldsubparagraph\subparagraph + \renewcommand{\subparagraph}[1]{\oldsubparagraph{#1}\mbox{}} +\fi +$endif$ +$endif$ +$if(pagestyle)$ +\pagestyle{$pagestyle$} +$endif$ +$if(csl-refs)$ +\newlength{\cslhangindent} +\setlength{\cslhangindent}{1.5em} +\newlength{\csllabelwidth} +\setlength{\csllabelwidth}{3em} +\newlength{\cslentryspacingunit} % times entry-spacing +\setlength{\cslentryspacingunit}{\parskip} +\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing + {% don't indent paragraphs + \setlength{\parindent}{0pt} + % turn on hanging indent if param 1 is 1 + \ifodd #1 + \let\oldpar\par + \def\par{\hangindent=\cslhangindent\oldpar} + \fi + % set entry spacing + \setlength{\parskip}{#2\cslentryspacingunit} + }% + {} +\usepackage{calc} +\newcommand{\CSLBlock}[1]{#1\hfill\break} +\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}} +\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break} +\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1} +$endif$ +$if(lang)$ +\ifLuaTeX +\usepackage[bidi=basic]{babel} +\else +\usepackage[bidi=default]{babel} +\fi +\babelprovide[main,import]{$babel-lang$} +$for(babel-otherlangs)$ +\babelprovide[import]{$babel-otherlangs$} +$endfor$ +% get rid of language-specific shorthands (see #6817): +\let\LanguageShortHands\languageshorthands +\def\languageshorthands#1{} +$endif$ +$for(header-includes)$ +$header-includes$ +$endfor$ +\ifLuaTeX + \usepackage{selnolig} % disable illegal ligatures +\fi +$if(dir)$ +\ifPDFTeX + \TeXXeTstate=1 + \newcommand{\RL}[1]{\beginR #1\endR} + \newcommand{\LR}[1]{\beginL #1\endL} + \newenvironment{RTL}{\beginR}{\endR} + \newenvironment{LTR}{\beginL}{\endL} +\fi +$endif$ +$if(natbib)$ +\usepackage[$natbiboptions$]{natbib} +\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} +$endif$ +$if(biblatex)$ +\usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex} +$for(bibliography)$ +\addbibresource{$bibliography$} +$endfor$ +$endif$ +$if(nocite-ids)$ +\nocite{$for(nocite-ids)$$it$$sep$, $endfor$} +$endif$ +$if(csquotes)$ +\usepackage{csquotes} +$endif$ + +$if(title)$ +\title{$title$$if(thanks)$\thanks{$thanks$}$endif$} +$endif$ +$if(subtitle)$ +$if(beamer)$ +$else$ +\usepackage{etoolbox} +\makeatletter +\providecommand{\subtitle}[1]{% add subtitle to \maketitle + \apptocmd{\@title}{\par {\large #1 \par}}{}{} +} +\makeatother +$endif$ +\subtitle{$subtitle$} +$endif$ +\author{$for(author)$$author$$sep$ \and $endfor$} +\date{$date$} +$if(beamer)$ +$if(institute)$ +\institute{$for(institute)$$institute$$sep$ \and $endfor$} +$endif$ +$if(titlegraphic)$ +\titlegraphic{\includegraphics{$titlegraphic$}} +$endif$ +$if(logo)$ +\logo{\includegraphics{$logo$}} +$endif$ +$endif$ + +\begin{document} +$if(has-frontmatter)$ +\frontmatter +$endif$ +$if(title)$ +$if(beamer)$ +\frame{\titlepage} +$else$ +\maketitle +$endif$ +$if(abstract)$ +\begin{abstract} +$abstract$ +\end{abstract} +$endif$ +$endif$ + +$for(include-before)$ +$include-before$ + +$endfor$ +$if(toc)$ +$if(toc-title)$ +\renewcommand*\contentsname{$toc-title$} +$endif$ +$if(beamer)$ +\begin{frame}[allowframebreaks] +$if(toc-title)$ + \frametitle{$toc-title$} +$endif$ + \tableofcontents[hideallsubsections] +\end{frame} +$else$ +{ +$if(colorlinks)$ +\hypersetup{linkcolor=$if(toccolor)$$toccolor$$else$$endif$} +$endif$ +\setcounter{tocdepth}{$toc-depth$} +\tableofcontents +} +$endif$ +$endif$ +$if(lof)$ +\listoffigures +$endif$ +$if(lot)$ +\listoftables +$endif$ +$if(linestretch)$ +\setstretch{$linestretch$} +$endif$ +$if(has-frontmatter)$ +\mainmatter +$endif$ +$body$ + +$if(has-frontmatter)$ +\backmatter +$endif$ +$if(natbib)$ +$if(bibliography)$ +$if(biblio-title)$ +$if(has-chapters)$ +\renewcommand\bibname{$biblio-title$} +$else$ +\renewcommand\refname{$biblio-title$} +$endif$ +$endif$ +$if(beamer)$ +\begin{frame}[allowframebreaks]{$biblio-title$} + \bibliographytrue +$endif$ + \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$} +$if(beamer)$ +\end{frame} +$endif$ + +$endif$ +$endif$ +$if(biblatex)$ +$if(beamer)$ +\begin{frame}[allowframebreaks]{$biblio-title$} + \bibliographytrue + \printbibliography[heading=none] +\end{frame} +$else$ +\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ +$endif$ + +$endif$ +$for(include-after)$ +$include-after$ + +$endfor$ +\end{document} From e95eb73d87e1d57124ace2f76fb71aa241935191 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Tue, 7 Jun 2022 12:59:02 +0200 Subject: [PATCH 7/7] chore(pdf): fix build, switch latex package --- nix/docker/default.nix | 4 ++-- routes | 20 +++++++++---------- shell.nix | 2 +- src/Handler/Admin/Test.hs | 7 ++++--- templates/i18n/admin-test/de-de-formal.hamlet | 9 ++++++--- templates/i18n/admin-test/en-eu.hamlet | 7 +++++-- 6 files changed, 28 insertions(+), 21 deletions(-) diff --git a/nix/docker/default.nix b/nix/docker/default.nix index 8cefccbe8..9fec469d5 100644 --- a/nix/docker/default.nix +++ b/nix/docker/default.nix @@ -22,8 +22,8 @@ let uniworx.uniworx.components.exes.uniworx prev.dockerTools.binSh findutils coreutils cups # needed for interface with print center - # texlive.combined.scheme-medium # Causes container to be too large! However, might be needed by the pandoc library to produce PDFs, but nix ought to include the necessary parts already - texlive.combined.scheme-basic # for PDFLaTeX for pandoc PDF creation + texlive.combined.scheme-medium # Causes container to be too large! However, might be needed by the pandoc library to produce PDFs, but nix ought to include the necessary parts already + #texlive.combined.scheme-basic # for PDFLaTeX for pandoc PDF creation # pandoc # just for manual testing within the pod, remove for production, since we use the library instead! curl wget netcat # just for manual testing within the pod, remove for production! openldap # just for manual testing within the pod, remove for production! diff --git a/routes b/routes index 7bb7d7520..3633b1e03 100644 --- a/routes +++ b/routes @@ -54,8 +54,8 @@ !/users/functionary-invite AdminFunctionaryInviteR GET POST !/users/add AdminUserAddR GET POST /admin AdminR GET -/admin/test AdminTestR GET POST -/admin/test/pdf AdminTestPdfR GET +/admin/test AdminTestR GET POST +/admin/test/pdf AdminTestPdfR GET /admin/errMsg AdminErrMsgR GET POST /admin/tokens AdminTokensR GET POST /admin/crontab AdminCrontabR GET @@ -69,7 +69,7 @@ /info/glossary GlossaryR GET !free /info/faq FaqR GET !free /version VersionR GET !free -/status StatusR GET !free +/status StatusR GET !free /help HelpR GET POST !free @@ -96,7 +96,7 @@ /grades EEGradesR GET POST !exam-office /staff-invite EEStaffInviteR GET POST /correct EECorrectR GET POST - + /term TermShowR GET !free /term/current TermCurrentR GET !free @@ -110,7 +110,7 @@ !/school/new SchoolNewR GET POST /school/#SchoolId SchoolR: / SchoolEditR GET POST - + /allocation/ AllocationListR GET !free !/allocation/new AllocationNewR GET POST !allocation-admin @@ -255,17 +255,17 @@ !/*WellKnownFileName WellKnownR GET !free --- for users -/qualification QualificationAllR GET !free -/qualification/#SchoolId QualificationSchoolR GET !free +-- for users +/qualification QualificationAllR GET !free +/qualification/#SchoolId QualificationSchoolR GET !free -- TODO /qualification/#SchoolId/#QualificationShorthand QualificationR GET !free -- must be logged in though -- OSIS CSV Export Demo /lms LmsAllR GET POST /lms/#SchoolId LmsSchoolR GET /lms/#SchoolId/#QualificationShorthand LmsR GET POST /lms/#SchoolId/#QualificationShorthand/edit LmsEditR GET POST -/lms/#SchoolId/#QualificationShorthand/users LmsUsersR GET -/lms/#SchoolId/#QualificationShorthand/users/direct LmsUsersDirectR GET +/lms/#SchoolId/#QualificationShorthand/users LmsUsersR GET +/lms/#SchoolId/#QualificationShorthand/users/direct LmsUsersDirectR GET /lms/#SchoolId/#QualificationShorthand/userlist LmsUserlistR GET POST /lms/#SchoolId/#QualificationShorthand/userlist/upload LmsUserlistUploadR GET POST /lms/#SchoolId/#QualificationShorthand/userlist/direct LmsUserlistDirectR POST diff --git a/shell.nix b/shell.nix index 7b085f90e..b979dbf80 100644 --- a/shell.nix +++ b/shell.nix @@ -71,6 +71,6 @@ let in pkgs.mkShell { name = "uni2work"; nativeBuildInputs = [develop inDevelop killallUni2work diffRunning] - ++ (with pkgs; [ nodejs-14_x postgresql_12 openldap google-chrome exiftool memcached minio minio-client gup skopeo texlive.combined.scheme-basic ]) + ++ (with pkgs; [ nodejs-14_x postgresql_12 openldap google-chrome exiftool memcached minio minio-client gup skopeo texlive.combined.scheme-medium ]) ++ (with pkgs.haskellPackages; [ stack yesod-bin hlint cabal-install weeder profiteur ]); } diff --git a/src/Handler/Admin/Test.hs b/src/Handler/Admin/Test.hs index 636f3d598..32230be1a 100644 --- a/src/Handler/Admin/Test.hs +++ b/src/Handler/Admin/Test.hs @@ -276,8 +276,8 @@ postAdminTestR = do getAdminTestPdfR :: Handler TypedContent getAdminTestPdfR = do - let -- typePDF = "application/pdf" :: ContentType - -- typePDF = Settings.Mime.mimeLookup "pdfdemo.pdf" + -- let -- typePDF = "application/pdf" :: ContentType + -- typePDF = Settings.Mime.mimeLookup "pdfdemo.pdf" content <- liftIO . P.runIO $ do tmpl <- P.compileDefaultTemplate "latex" let @@ -285,7 +285,8 @@ getAdminTestPdfR = do texopts = [] writeropts = def { P.writerTemplate = Just tmpl } doc <- P.readMarkdown def md - P.makePDF "pdflatex" texopts P.writeLaTeX writeropts doc + P.makePDF "pdflatex" texopts P.writeLaTeX writeropts doc -- xcolor.sty not found + -- P.makePDF "lualatex" texopts P.writeLaTeX writeropts doc -- unicode-math.sty not found case content of Right (Right bs) -> do liftIO $ L.writeFile "generated.pdf" bs diff --git a/templates/i18n/admin-test/de-de-formal.hamlet b/templates/i18n/admin-test/de-de-formal.hamlet index 49a1a0a8d..f381b6189 100644 --- a/templates/i18n/admin-test/de-de-formal.hamlet +++ b/templates/i18n/admin-test/de-de-formal.hamlet @@ -66,6 +66,9 @@ Some icons: ^{isVisible False} ^{hasComment True}
    -

    Download a generated PDF - Here is a - Download-Link \ No newline at end of file +

    + Erzeugtes PDF herunterladen: + Hier ist ein + + Download-Link + für eine PDF Vorschau. \ No newline at end of file diff --git a/templates/i18n/admin-test/en-eu.hamlet b/templates/i18n/admin-test/en-eu.hamlet index 0c4b856b0..c45ee9bb4 100644 --- a/templates/i18n/admin-test/en-eu.hamlet +++ b/templates/i18n/admin-test/en-eu.hamlet @@ -67,6 +67,9 @@ Some icons: ^{isVisible False} ^{hasComment True}
    -

    Download a generated PDF +

    + Download a generated PDF Here is a - Download-Link \ No newline at end of file + + Download-Link + for a preview. \ No newline at end of file