latex-package.eclass 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. # Copyright 1999-2016 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # @ECLASS: latex-package.eclass
  4. # @MAINTAINER:
  5. # TeX team <tex@gentoo.org>
  6. # @AUTHOR:
  7. # Matthew Turk <satai@gentoo.org>
  8. # Martin Ehmsen <ehmsen@gentoo.org>
  9. # @BLURB: An eclass for easy installation of LaTeX packages
  10. # @DESCRIPTION:
  11. # This eClass is designed to be easy to use and implement. The vast majority of
  12. # LaTeX packages will only need to define SRC_URI (and sometimes S) for a
  13. # successful installation. If fonts need to be installed, then the variable
  14. # SUPPLIER must also be defined.
  15. #
  16. # However, those packages that contain subdirectories must process each
  17. # subdirectory individually. For example, a package that contains directories
  18. # DIR1 and DIR2 must call latex-package_src_compile() and
  19. # latex-package_src_install() in each directory, as shown here:
  20. #
  21. # src_compile() {
  22. # cd ${S}
  23. # cd DIR1
  24. # latex-package_src_compile
  25. # cd ..
  26. # cd DIR2
  27. # latex-package_src_compile
  28. # }
  29. #
  30. # src_install() {
  31. # cd ${S}
  32. # cd DIR1
  33. # latex-package_src_install
  34. # cd ..
  35. # cd DIR2
  36. # latex-package_src_install
  37. # }
  38. #
  39. # The eClass automatically takes care of rehashing TeX's cache (ls-lR) after
  40. # installation and after removal, as well as creating final documentation from
  41. # TeX files that come with the source. Note that we break TeX layout standards
  42. # by placing documentation in /usr/share/doc/${PN}
  43. #
  44. # For examples of basic installations, check out dev-tex/aastex and
  45. # dev-tex/leaflet .
  46. #
  47. # NOTE: The CTAN "directory grab" function creates files with different MD5
  48. # signatures EVERY TIME. For this reason, if you are grabbing from the CTAN,
  49. # you must either grab each file individually, or find a place to mirror an
  50. # archive of them. (iBiblio)
  51. #
  52. # It inherits base and eutils in EAPI 5 and earlier.
  53. case ${EAPI:-0} in
  54. 0|1|2|3|4|5) inherit base eutils ;;
  55. 6) ;;
  56. *) die "Unknown EAPI ${EAPI} for ${ECLASS}" ;;
  57. esac
  58. RDEPEND="virtual/latex-base"
  59. DEPEND="${RDEPEND}
  60. >=sys-apps/texinfo-4.2-r5"
  61. HOMEPAGE="http://www.tug.org/"
  62. TEXMF="/usr/share/texmf-site"
  63. # @ECLASS-VARIABLE: SUPPLIER
  64. # @DESCRIPTION:
  65. # This refers to the font supplier; it should be overridden (see eclass
  66. # DESCRIPTION above)
  67. SUPPLIER="misc"
  68. # @ECLASS-VARIABLE: LATEX_DOC_ARGUMENTS
  69. # @DESCRIPTION:
  70. # When compiling documentation (.tex/.dtx), this variable will be passed
  71. # to pdflatex as additional argument (e.g. -shell-escape). This variable
  72. # must be set after inherit, as it gets automatically cleared otherwise.
  73. LATEX_DOC_ARGUMENTS=""
  74. # Kept for backwards compatibility
  75. latex-package_has_tetex_3() {
  76. case ${EAPI:-0} in
  77. 0|1|2|3|4|5) return 0 ;;
  78. *) die "${FUNCNAME} no longer supported in EAPI ${EAPI}" ;;
  79. esac
  80. }
  81. # @FUNCTION: latex-package_src_doinstall
  82. # @USAGE: [ module ]
  83. # @DESCRIPTION:
  84. # [module] can be one or more of: sh, sty, cls, fd, clo, def, cfg, dvi, ps, pdf,
  85. # tex, dtx, tfm, vf, afm, pfb, ttf, bst, styles, doc, fonts, bin, or all.
  86. # If [module] is not given, all is assumed.
  87. # It installs the files found in the current directory to the standard locations
  88. # for a TeX installation
  89. latex-package_src_doinstall() {
  90. debug-print function $FUNCNAME $*
  91. # Avoid generating font cache outside of the sandbox
  92. export VARTEXFONTS="${T}/fonts"
  93. # This actually follows the directions for a "single-user" system
  94. # at http://www.ctan.org/installationadvice/ modified for gentoo.
  95. [ -z "$1" ] && latex-package_src_install all
  96. while [ "$1" ]; do
  97. case $1 in
  98. "sh")
  99. for i in `find . -maxdepth 1 -type f -name "*.${1}"`
  100. do
  101. dobin $i || die "dobin $i failed"
  102. done
  103. ;;
  104. "sty" | "cls" | "fd" | "clo" | "def" | "cfg")
  105. for i in `find . -maxdepth 1 -type f -name "*.${1}"`
  106. do
  107. insinto ${TEXMF}/tex/latex/${PN}
  108. doins $i || die "doins $i failed"
  109. done
  110. ;;
  111. "dvi" | "ps" | "pdf")
  112. for i in `find . -maxdepth 1 -type f -name "*.${1}"`
  113. do
  114. insinto /usr/share/doc/${PF}
  115. doins $i || die "doins $i failed"
  116. dosym /usr/share/doc/${PF}/$(basename ${i}) ${TEXMF}/doc/latex/${PN}/${i}
  117. case "${EAPI:-0}" in
  118. 0|1|2|3) ;;
  119. *)
  120. # prevent compression of symlink target
  121. docompress -x /usr/share/doc/${PF}/$(basename ${i})
  122. ;;
  123. esac
  124. done
  125. ;;
  126. "tex" | "dtx")
  127. if ! in_iuse doc || use doc ; then
  128. for i in `find . -maxdepth 1 -type f -name "*.${1}"`
  129. do
  130. [ -n "${LATEX_PACKAGE_SKIP}" ] && has ${i##*/} ${LATEX_PACKAGE_SKIP} && continue
  131. einfo "Making documentation: $i"
  132. if pdflatex ${LATEX_DOC_ARGUMENTS} --interaction=batchmode $i &> /dev/null ; then
  133. pdflatex ${LATEX_DOC_ARGUMENTS} --interaction=batchmode $i &> /dev/null || die
  134. else
  135. einfo "pdflatex failed, trying texi2dvi"
  136. texi2dvi -q -c --language=latex $i &> /dev/null || die
  137. fi
  138. done
  139. fi
  140. ;;
  141. "tfm" | "vf" | "afm")
  142. for i in `find . -maxdepth 1 -type f -name "*.${1}"`
  143. do
  144. insinto ${TEXMF}/fonts/${1}/${SUPPLIER}/${PN}
  145. doins $i || die "doins $i failed"
  146. done
  147. ;;
  148. "pfb")
  149. for i in `find . -maxdepth 1 -type f -name "*.pfb"`
  150. do
  151. insinto ${TEXMF}/fonts/type1/${SUPPLIER}/${PN}
  152. doins $i || die "doins $i failed"
  153. done
  154. ;;
  155. "ttf")
  156. for i in `find . -maxdepth 1 -type f -name "*.ttf"`
  157. do
  158. insinto ${TEXMF}/fonts/truetype/${SUPPLIER}/${PN}
  159. doins $i || die "doins $i failed"
  160. done
  161. ;;
  162. "bst")
  163. for i in `find . -maxdepth 1 -type f -name "*.bst"`
  164. do
  165. insinto ${TEXMF}/bibtex/bst/${PN}
  166. doins $i || die "doins $i failed"
  167. done
  168. ;;
  169. "styles")
  170. latex-package_src_doinstall sty cls fd clo def cfg bst
  171. ;;
  172. "doc")
  173. latex-package_src_doinstall tex dtx dvi ps pdf
  174. ;;
  175. "fonts")
  176. latex-package_src_doinstall tfm vf afm pfb ttf
  177. ;;
  178. "bin")
  179. latex-package_src_doinstall sh
  180. ;;
  181. "all")
  182. latex-package_src_doinstall styles fonts bin doc
  183. ;;
  184. esac
  185. shift
  186. done
  187. }
  188. # @FUNCTION: latex-package_src_compile
  189. # @DESCRIPTION:
  190. # Calls latex for each *.ins in the current directory in order to generate the
  191. # relevant files that will be installed
  192. latex-package_src_compile() {
  193. debug-print function $FUNCNAME $*
  194. for i in `find \`pwd\` -maxdepth 1 -type f -name "*.ins"`
  195. do
  196. einfo "Extracting from $i"
  197. latex --interaction=batchmode $i &> /dev/null || die
  198. done
  199. }
  200. # @FUNCTION: latex-package_src_install
  201. # @DESCRIPTION:
  202. # Installs the package
  203. latex-package_src_install() {
  204. debug-print function $FUNCNAME $*
  205. latex-package_src_doinstall all
  206. if [ -n "${DOCS}" ] ; then
  207. dodoc ${DOCS}
  208. fi
  209. }
  210. # @FUNCTION: latex-package_pkg_postinst
  211. # @DESCRIPTION:
  212. # Calls latex-package_rehash to ensure the TeX installation is consistent with
  213. # the kpathsea database
  214. latex-package_pkg_postinst() {
  215. debug-print function $FUNCNAME $*
  216. latex-package_rehash
  217. }
  218. # @FUNCTION: latex-package_pkg_postrm
  219. # @DESCRIPTION:
  220. # Calls latex-package_rehash to ensure the TeX installation is consistent with
  221. # the kpathsea database
  222. latex-package_pkg_postrm() {
  223. debug-print function $FUNCNAME $*
  224. latex-package_rehash
  225. }
  226. # @FUNCTION: latex-package_rehash
  227. # @DESCRIPTION:
  228. # Rehashes the kpathsea database, according to the current TeX installation
  229. latex-package_rehash() {
  230. debug-print function $FUNCNAME $*
  231. texmf-update
  232. }
  233. EXPORT_FUNCTIONS src_compile src_install pkg_postinst pkg_postrm