1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
4 # @ECLASS: latex-package.eclass
6 # TeX team <tex@gentoo.org>
8 # Matthew Turk <satai@gentoo.org>
9 # Martin Ehmsen <ehmsen@gentoo.org>
11 # @BLURB: An eclass for easy installation of LaTeX packages
13 # This eClass is designed to be easy to use and implement. The vast majority of
14 # LaTeX packages will only need to define SRC_URI (and sometimes S) for a
15 # successful installation. If fonts need to be installed, then the variable
16 # SUPPLIER must also be defined.
18 # However, those packages that contain subdirectories must process each
19 # subdirectory individually. For example, a package that contains directories
20 # DIR1 and DIR2 must call latex-package_src_compile() and
21 # latex-package_src_install() in each directory, as shown here:
26 # latex-package_src_compile
29 # latex-package_src_compile
35 # latex-package_src_install
38 # latex-package_src_install
41 # The eClass automatically takes care of rehashing TeX's cache (ls-lR) after
42 # installation and after removal, as well as creating final documentation from
43 # TeX files that come with the source. Note that we break TeX layout standards
44 # by placing documentation in /usr/share/doc/${PN}
46 # For examples of basic installations, check out dev-tex/aastex and
49 # NOTE: The CTAN "directory grab" function creates files with different MD5
50 # signatures EVERY TIME. For this reason, if you are grabbing from the CTAN,
51 # you must either grab each file individually, or find a place to mirror an
52 # archive of them. (iBiblio)
54 if [[ -z ${_LATEX_PACKAGE_ECLASS} ]]; then
55 _LATEX_PACKAGE_ECLASS=1
57 RDEPEND="virtual/latex-base"
59 >=sys-apps/texinfo-4.2-r5"
63 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;;
65 *) die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
68 HOMEPAGE="http://www.tug.org/"
69 TEXMF="/usr/share/texmf-site"
71 # @ECLASS-VARIABLE: SUPPLIER
73 # This refers to the font supplier; it should be overridden (see eclass
77 # @ECLASS-VARIABLE: LATEX_DOC_ARGUMENTS
79 # When compiling documentation (.tex/.dtx), this variable will be passed
80 # to pdflatex as additional argument (e.g. -shell-escape). This variable
81 # must be set after inherit, as it gets automatically cleared otherwise.
82 LATEX_DOC_ARGUMENTS=""
84 # @FUNCTION: latex-package_src_doinstall
87 # [module] can be one or more of: sh, sty, cls, fd, clo, def, cfg, dvi, ps, pdf,
88 # tex, dtx, tfm, vf, afm, pfb, ttf, bst, styles, doc, fonts, bin, or all.
89 # If [module] is not given, all is assumed.
90 # It installs the files found in the current directory to the standard locations
91 # for a TeX installation
92 latex-package_src_doinstall() {
93 debug-print function $FUNCNAME $*
95 # Avoid generating font cache outside of the sandbox
96 export VARTEXFONTS="${T}/fonts"
98 # This actually follows the directions for a "single-user" system
99 # at http://www.ctan.org/installationadvice/ modified for gentoo.
100 [[ -z ${1} ]] && latex-package_src_install all
105 while IFS= read -r -d '' i; do
107 done < <(find -maxdepth 1 -type f -name "*.${1}" -print0)
110 "sty" | "cls" | "fd" | "clo" | "def" | "cfg")
111 while IFS= read -r -d '' i; do
112 insinto ${TEXMF}/tex/latex/${PN}
114 done < <(find -maxdepth 1 -type f -name "*.${1}" -print0)
117 "dvi" | "ps" | "pdf")
118 while IFS= read -r -d '' i; do
119 insinto /usr/share/doc/${PF}
121 dosym /usr/share/doc/${PF}/$(basename ${i}) ${TEXMF}/doc/latex/${PN}/${i}
122 docompress -x /usr/share/doc/${PF}/$(basename ${i})
123 done < <(find -maxdepth 1 -type f -name "*.${1}" -print0)
127 if ! in_iuse doc || use doc ; then
128 while IFS= read -r -d '' i; do
129 [[ -n ${LATEX_PACKAGE_SKIP} ]] &&
130 has ${i##*/} ${LATEX_PACKAGE_SKIP} &&
133 einfo "Making documentation: ${i}"
134 # some macros need compiler called twice, do it here.
135 set -- pdflatex ${LATEX_DOC_ARGUMENTS} --halt-on-error --interaction=nonstopmode ${i}
139 einfo "pdflatex failed, trying texi2dvi"
140 texi2dvi -q -c --language=latex ${i} || die
142 done < <(find -maxdepth 1 -type f -name "*.${1}" -print0)
146 "tfm" | "vf" | "afm")
147 while IFS= read -r -d '' i; do
148 insinto ${TEXMF}/fonts/${1}/${SUPPLIER}/${PN}
150 done < <(find -maxdepth 1 -type f -name "*.${1}" -print0)
154 while IFS= read -r -d '' i; do
155 insinto ${TEXMF}/fonts/type1/${SUPPLIER}/${PN}
157 done < <(find -maxdepth 1 -type f -name "*.pfb" -print0)
160 while IFS= read -r -d '' i; do
161 insinto ${TEXMF}/fonts/truetype/${SUPPLIER}/${PN}
163 done < <(find -maxdepth 1 -type f -name "*.ttf" -print0)
166 while IFS= read -r -d '' i; do
167 insinto ${TEXMF}/bibtex/bst/${PN}
169 done < <(find -maxdepth 1 -type f -name "*.bst" -print0)
173 latex-package_src_doinstall sty cls fd clo def cfg bst
177 latex-package_src_doinstall tex dtx dvi ps pdf
181 latex-package_src_doinstall tfm vf afm pfb ttf
185 latex-package_src_doinstall sh
189 latex-package_src_doinstall styles fonts bin doc
196 # @FUNCTION: latex-package_src_compile
198 # Calls latex for each *.ins in the current directory in order to generate the
199 # relevant files that will be installed
200 latex-package_src_compile() {
201 debug-print function $FUNCNAME $*
202 while IFS= read -r -d '' i; do
203 einfo "Extracting from ${i}"
204 latex --halt-on-error --interaction=nonstopmode ${i} || die
205 done < <(find -maxdepth 1 -type f -name "*.ins" -print0)
208 # @FUNCTION: latex-package_src_install
210 # Installs the package
211 latex-package_src_install() {
212 debug-print function $FUNCNAME $*
213 latex-package_src_doinstall all
217 # @FUNCTION: latex-package_pkg_postinst
219 # Calls latex-package_rehash to ensure the TeX installation is consistent with
220 # the kpathsea database
221 latex-package_pkg_postinst() {
222 debug-print function $FUNCNAME $*
226 # @FUNCTION: latex-package_pkg_postrm
228 # Calls latex-package_rehash to ensure the TeX installation is consistent with
229 # the kpathsea database
230 latex-package_pkg_postrm() {
231 debug-print function $FUNCNAME $*
235 # @FUNCTION: latex-package_rehash
237 # Rehashes the kpathsea database, according to the current TeX installation
238 latex-package_rehash() {
239 debug-print function $FUNCNAME $*
243 EXPORT_FUNCTIONS src_compile src_install pkg_postinst pkg_postrm