{"id":83,"date":"2019-03-17T15:54:00","date_gmt":"2019-03-17T06:54:00","guid":{"rendered":"https:\/\/blog.interstellar.co.jp\/en\/?p=83"},"modified":"2022-07-15T16:33:02","modified_gmt":"2022-07-15T07:33:02","slug":"sphinx-pdf","status":"publish","type":"post","link":"https:\/\/blog.interstellar.co.jp\/en\/2019\/03\/17\/sphinx-pdf\/","title":{"rendered":"Setting up an environment for PDF output from Sphinx via TeX"},"content":{"rendered":"\n<p>Hi, I&#8217;m agata.<\/p>\n\n\n\n<p>In our company, we write various documents in Sphinx and build them in Netlify via GitLab so that they can be viewed in a web browser. This is usually sufficient, but it can be a little inconvenient if you need to attach them to an email or output them to paper for various reasons.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Envirnment<\/h2>\n\n\n\n<p>As usual, I will assume my environment. My documentation environment is as follows.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>MacBook<\/li><li>macOS High Sierra (10.13.6)<\/li><li>Homebrew 2.0.4<ul><li>Homebrew\/homebrew-core (git revision a290; last commit 2019-03-16)<\/li><li>Homebrew\/homebrew-cask (git revision 3db818; last commit 2019-03-17)<\/li><\/ul><\/li><li>Sphinx 1.8.0<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Installing TeX<\/h2>\n\n\n\n<p>To generate PDFs from Sphinx, you need to go through TeX. For this reason, a TeX processing environment is required; on macOS, this can be easily installed using Homebrew.<\/p>\n\n\n\n<pre class=\"wp-block-code is-style-dark\"><code>$ brew cask install mactex<\/code><\/pre>\n\n\n\n<p>Depending on the environment, it can take quite a long time due to the large size of the TeX package. Take your time and wait.<\/p>\n\n\n\n<pre class=\"wp-block-code is-style-dark\"><code>==&gt; Satisfying dependencies\n ==&gt; Installing Formula dependencies: ghostscript\n ==&gt; Installing dependencies for ghostscript: libtiff\n ==&gt; Installing ghostscript dependency: libtiff\n ==&gt; Downloading https:\/\/homebrew.bintray.com\/bottles\/libtiff-4.0.10_1.high_sierra.bottle.tar.gz\n ################################################################## 100.0%\n ==&gt; Pouring libtiff-4.0.10_1.high_sierra.bottle.tar.gz\n ?  \/usr\/local\/Cellar\/libtiff\/4.0.10_1: 246 files, 3.5MB\n ==&gt; Installing ghostscript\n ==&gt; Downloading https:\/\/homebrew.bintray.com\/bottles\/ghostscript-9.26_1.high_sierra.bottle.tar.gz\n ################################################################## 100.0%\n ==&gt; Pouring ghostscript-9.26_1.high_sierra.bottle.tar.gz\n ?  \/usr\/local\/Cellar\/ghostscript\/9.26_1: 668 files, 81.1MB\n ==&gt; Downloading http:\/\/mirror.ctan.org\/systems\/mac\/mactex\/mactex-20180417.pkg\n ==&gt; Downloading from ftp:\/\/ftp.kddilabs.jp\/CTAN\/systems\/mac\/mactex\/mactex-20180417.pkg\n ################################################################## 100.0%\n ==&gt; Verifying SHA-256 checksum for Cask 'mactex'.\n ==&gt; Installing Cask mactex\n ==&gt; Running installer for mactex; your password may be necessary.\n ==&gt; Package installers may write to any location; options such as --appdir are ignored.\n Password:<\/code><\/pre>\n\n\n\n<p>When the mactex installation starts, you will be asked for your password, which you should enter. Again, this will take more time&#8230;&#8230;..<\/p>\n\n\n\n<pre class=\"wp-block-code is-style-dark\"><code>installer: Package name is MacTeX-2018\n installer: choices changes file '\/var\/folders\/tg\/lt98nx792tj67l35cv39860c0000gn\/T\/choices20190317-6954-hjcb0m.xml' applied\n installer: Installing at base path \/\n installer: The install was successful.\n ?  mactex was successfully installed!<\/code><\/pre>\n\n\n\n<p>You have now installed TeX.<br>So far, the following have been installed<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>TeX Live-2018<\/li><li>GUI Applications<ul><li>BibDesk<\/li><li>LaTeXiT<\/li><li>TeX Live Utility<\/li><li>TeXShop<\/li><\/ul><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">TeX Live updates.<\/h2>\n\n\n\n<p>Update the TeX Live installed with the tlmgr command.<br>In the terminal where the brew command was executed, the tlmgr command is not passed through because the environment variables have not been updated. Open a new terminal and the environment variables will be set, so run the following commands in the new terminal.<\/p>\n\n\n\n<pre class=\"wp-block-code is-style-dark\"><code>$ sudo tlmgr update --self --all<\/code><\/pre>\n\n\n\n<p>This also takes a lot of time\u2026 Take your time and wait.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Default paper size settings<\/h2>\n\n\n\n<p>Do the default settings for paper size. Here it is set to A4.<\/p>\n\n\n\n<pre class=\"wp-block-code is-style-dark\"><code>$ sudo tlmgr paper a4<\/code><\/pre>\n\n\n\n<p>The installation and configuration of TeX is now complete. Although it takes some time, it is very easy and very helpful. I was so thankful and grateful when I was a student that I had to say &#8220;hooray&#8221; to set up the TeX environment\u2026<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Generating PDFs from Sphinx<\/h2>\n\n\n\n<p>Once TeX has been set up, PDFs can be generated from Sphinx.<br>Run the following command in the Sphinx directory.<\/p>\n\n\n\n<pre class=\"wp-block-code is-style-dark\"><code>$ make latexpdf<\/code><\/pre>\n\n\n\n<p>If there are no problems, a latex folder is created at the build destination, and TeX-related files and PDF files are generated.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, I&#8217;m agata. In our company, we write various documents in Sphinx and build them in Netlify via GitLab so that they can be viewed in a web browser. This is usually sufficient, but it can be a little inconvenient if you need to attach them to an email or output them to paper for various reasons. Envirnment As usual, I will assume my environment. My documentation environment is as follows. MacBook macOS High Sierra (10.13.6) Homebrew 2.0.4 Homebrew\/homebrew-core (git revision a290; last commit 2019-03-16) Homebrew\/homebrew-cask (git revision 3db818; last commit 2019-03-17) Sphinx 1.8.0 Installing TeX To generate PDFs from Sphinx, you need to go through TeX. For this reason,&#8230;<\/p>\n","protected":false},"author":2,"featured_media":86,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"vkexunit_cta_each_option":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-83","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/posts\/83","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/comments?post=83"}],"version-history":[{"count":2,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/posts\/83\/revisions"}],"predecessor-version":[{"id":88,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/posts\/83\/revisions\/88"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/media\/86"}],"wp:attachment":[{"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/media?parent=83"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/categories?post=83"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.interstellar.co.jp\/en\/wp-json\/wp\/v2\/tags?post=83"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}