dev-python/hypothesis: Bump to 5.8.3
[gentoo.git] / eclass / latex-package.eclass
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: latex-package.eclass
5 # @MAINTAINER:
6 # TeX team <tex@gentoo.org>
7 # @AUTHOR:
8 # Matthew Turk <satai@gentoo.org>
9 # Martin Ehmsen <ehmsen@gentoo.org>
10 # @SUPPORTED_EAPIS: 7
11 # @BLURB: An eclass for easy installation of LaTeX packages
12 # @DESCRIPTION:
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.
17 #
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:
22 #
23 # src_compile() {
24 #    cd ${S}
25 #    cd DIR1
26 #    latex-package_src_compile
27 #    cd ..
28 #    cd DIR2
29 #    latex-package_src_compile
30 # }
31 #
32 # src_install() {
33 #    cd ${S}
34 #    cd DIR1
35 #    latex-package_src_install
36 #    cd ..
37 #    cd DIR2
38 #    latex-package_src_install
39 # }
40 #
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}
45 #
46 # For examples of basic installations, check out dev-tex/aastex and
47 # dev-tex/leaflet .
48 #
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)
53
54 if [[ -z ${_LATEX_PACKAGE_ECLASS} ]]; then
55 _LATEX_PACKAGE_ECLASS=1
56
57 RDEPEND="virtual/latex-base"
58 DEPEND="${RDEPEND}
59         >=sys-apps/texinfo-4.2-r5"
60
61 case ${EAPI:-0} in
62         [0-6])
63                 die "Unsupported EAPI=${EAPI:-0} (too old) for ${ECLASS}" ;;
64         7)      ;;
65         *)      die "Unsupported EAPI=${EAPI} (unknown) for ${ECLASS}" ;;
66 esac
67
68 HOMEPAGE="http://www.tug.org/"
69 TEXMF="/usr/share/texmf-site"
70
71 # @ECLASS-VARIABLE: SUPPLIER
72 # @DESCRIPTION:
73 # This refers to the font supplier; it should be overridden (see eclass
74 # DESCRIPTION above)
75 SUPPLIER="misc"
76
77 # @ECLASS-VARIABLE: LATEX_DOC_ARGUMENTS
78 # @DESCRIPTION:
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=""
83
84 # @FUNCTION: latex-package_src_doinstall
85 # @USAGE: [ module ]
86 # @DESCRIPTION:
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 $*
94
95         # Avoid generating font cache outside of the sandbox
96         export VARTEXFONTS="${T}/fonts"
97
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
101
102         while [[ ${1} ]]; do
103                 case ${1} in
104                         "sh")
105                                 while IFS= read -r -d '' i; do
106                                         dobin ${i}
107                                 done < <(find -maxdepth 1 -type f -name "*.${1}" -print0)
108                                 ;;
109
110                         "sty" | "cls" | "fd" | "clo" | "def" | "cfg")
111                                 while IFS= read -r -d '' i; do
112                                         insinto ${TEXMF}/tex/latex/${PN}
113                                         doins ${i}
114                                 done < <(find -maxdepth 1 -type f -name "*.${1}" -print0)
115                                 ;;
116
117                         "dvi" | "ps" | "pdf")
118                                 while IFS= read -r -d '' i; do
119                                         insinto /usr/share/doc/${PF}
120                                         doins ${i}
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)
124                                 ;;
125
126                         "tex" | "dtx")
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} &&
131                                                 continue
132
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}
136                                                 if "${@}"; then
137                                                         "${@}"
138                                                 else
139                                                         einfo "pdflatex failed, trying texi2dvi"
140                                                         texi2dvi -q -c --language=latex ${i} || die
141                                                 fi
142                                         done < <(find -maxdepth 1 -type f -name "*.${1}" -print0)
143                                 fi
144                                 ;;
145
146                         "tfm" | "vf" | "afm")
147                                 while IFS= read -r -d '' i; do
148                                         insinto ${TEXMF}/fonts/${1}/${SUPPLIER}/${PN}
149                                         doins ${i}
150                                 done < <(find -maxdepth 1 -type f -name "*.${1}" -print0)
151                                 ;;
152
153                         "pfb")
154                                 while IFS= read -r -d '' i; do
155                                         insinto ${TEXMF}/fonts/type1/${SUPPLIER}/${PN}
156                                         doins ${i}
157                                 done < <(find -maxdepth 1 -type f -name "*.pfb" -print0)
158                                 ;;
159                         "ttf")
160                                 while IFS= read -r -d '' i; do
161                                         insinto ${TEXMF}/fonts/truetype/${SUPPLIER}/${PN}
162                                         doins ${i}
163                                 done < <(find -maxdepth 1 -type f -name "*.ttf" -print0)
164                                 ;;
165                         "bst")
166                                 while IFS= read -r -d '' i; do
167                                         insinto ${TEXMF}/bibtex/bst/${PN}
168                                         doins ${i}
169                                 done < <(find -maxdepth 1 -type f -name "*.bst" -print0)
170                                 ;;
171
172                         "styles")
173                                 latex-package_src_doinstall sty cls fd clo def cfg bst
174                                 ;;
175
176                         "doc")
177                                 latex-package_src_doinstall tex dtx dvi ps pdf
178                                 ;;
179
180                         "fonts")
181                                 latex-package_src_doinstall tfm vf afm pfb ttf
182                                 ;;
183
184                         "bin")
185                                 latex-package_src_doinstall sh
186                                 ;;
187
188                         "all")
189                                 latex-package_src_doinstall styles fonts bin doc
190                                 ;;
191                 esac
192         shift
193         done
194 }
195
196 # @FUNCTION: latex-package_src_compile
197 # @DESCRIPTION:
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)
206 }
207
208 # @FUNCTION: latex-package_src_install
209 # @DESCRIPTION:
210 # Installs the package
211 latex-package_src_install() {
212         debug-print function $FUNCNAME $*
213         latex-package_src_doinstall all
214         einstalldocs
215 }
216
217 # @FUNCTION: latex-package_pkg_postinst
218 # @DESCRIPTION:
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 $*
223         latex-package_rehash
224 }
225
226 # @FUNCTION: latex-package_pkg_postrm
227 # @DESCRIPTION:
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 $*
232         latex-package_rehash
233 }
234
235 # @FUNCTION: latex-package_rehash
236 # @DESCRIPTION:
237 # Rehashes the kpathsea database, according to the current TeX installation
238 latex-package_rehash() {
239         debug-print function $FUNCNAME $*
240         texmf-update
241 }
242
243 EXPORT_FUNCTIONS src_compile src_install pkg_postinst pkg_postrm
244
245 fi