# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           texlive 1.0

name                texlive-latex-extra
version             78229
revision            4

categories          tex
maintainers         {dports @drkp}
license             Copyleft Permissive
description         TeX Live: LaTeX additional packages
long_description    A very large collection of add-on packages for LaTeX.

checksums           texlive-latex-extra-78229-run.tar.xz \
                    rmd160  71ba90157592585770a01f13328bad9d1fd2165b \
                    sha256  6b978d420ea8f8407677362ce5020b443ba60b445149a3d784ffc32f0aa5f7a0 \
                    size    37848116 \
                    texlive-latex-extra-78229-doc.tar.xz \
                    rmd160  4b92b70fb1f80d73e0bdd207c6b26f24ac768546 \
                    sha256  57f688c682f1ebe466cba411036cbf620446410586f373a3f617243d4c2a0647 \
                    size    819652896 \
                    texlive-latex-extra-78229-src.tar.xz \
                    rmd160  5fb05f82ed5fd06b73f4ac9cd45ab684cc0b6585 \
                    sha256  8009f6bdd538c34fa4cc094bbee9698055858dbaf5b501f8a8481e139487a518 \
                    size    20808160

depends_lib         port:texlive-latex-recommended port:texlive-pictures

texlive.formats      \
    {1 dvilualatex-dev luatex language.dat,language.dat.lua {dvilualatex.ini}} \
    {1 latex-dev pdftex language.dat {-translate-file=cp227.tcx *latex.ini}} \
    {1 lualatex-dev luahbtex language.dat,language.dat.lua {lualatex.ini}} \
    {1 pdflatex-dev pdftex language.dat {-translate-file=cp227.tcx *pdflatex.ini}}

texlive.maps      \
    {Map epiolmec.map} \
    {MixedMap esint.map} \
    {Map mathalpha.map} \
    {Map scanpages.map}

texlive.binaries    authorindex bookshelf-listallfonts bookshelf-mkfontsel dvilualatex-dev exceltex hyperxmp-add-bytecount l3build latex-dev latexminted lualatex-dev makedtx makeglossaries makeglossaries-lite markdown2tex pagelayoutapi pdfannotextractor pdflatex-dev perltex pygmentex splitindex svn-multi textestvis typog-grep vpe webquiz wordcount yplan

PortGroup           perl5 1.0

perl5.branches      5.34

# Pin Python scripts to correct interpreter. pygmentex imports the pygments
# module.
set python_branch   3.14
set python_ver      [string map {. {}} ${python_branch}]
depends_run-append  port:python${python_ver} \
                    port:py${python_ver}-pygments

# Fix perl paths for any perl scripts that have non-core dependencies.
post-patch {
    reinplace -E "1 s,^#! ?(/usr/bin/env perl|/usr/bin/perl),#!${prefix}/bin/perl${perl5.major}," \
        ${worksrcpath}/runfiles/texmf-dist/scripts/pax/pdfannotextractor.pl \
        ${worksrcpath}/runfiles/texmf-dist/scripts/svn-multi/svn-multi.pl

    # Pin Python scripts to correct interpreter
    reinplace -E "1 s,^#! ?(/usr/bin/env python3?|/usr/bin/python)( -O)?\$,#!${prefix}/bin/python${python_branch}," \
        ${worksrcpath}/runfiles/texmf-dist/scripts/changes/pyMergeChanges.py \
        ${worksrcpath}/runfiles/texmf-dist/scripts/minted/latexminted.py \
        ${worksrcpath}/runfiles/texmf-dist/scripts/pygmentex/pygmentex.py \
        ${worksrcpath}/runfiles/texmf-dist/scripts/webquiz/webquiz \
        ${worksrcpath}/runfiles/texmf-dist/scripts/webquiz/webquiz.py \
        ${worksrcpath}/runfiles/texmf-dist/scripts/webquiz/webquiz_makequiz.py \
        ${worksrcpath}/runfiles/texmf-dist/scripts/webquiz/webquiz_util.py
}

# dependencies for pdfannotextractor
depends_run-append  port:p${perl5.major}-file-which

# dependencies for svn-multi
depends_run-append  port:p${perl5.major}-timedate

# Rename 'wordcount' to avoid conflict with EMBOSS.
# https://trac.macports.org/ticket/70894
post-destroot {
    file rename ${destroot}${prefix}/bin/wordcount \
                ${destroot}${prefix}/bin/latex-wordcount
}

texlive.texmfport

# Update minted independently of the TeX Live collection snapshot.  The Python
# release source archive also contains the matching minted 3.8.0 TeX files.
set latexminted_version 0.7.1
master_sites-append https://github.com/gpoore/minted/archive/refs/tags/python/:minted \
                    https://github.com/gpoore/minted/releases/download/python/v${latexminted_version}/:latexminted

# Only the original TeX Live archives use xz compression.
extract.only        ${distname}-run${extract.suffix}
if {[variant_isset doc]} {
    extract.only-append ${distname}-doc${extract.suffix}
}
if {[variant_isset src]} {
    extract.only-append ${distname}-src${extract.suffix}
}

distfiles-append    v${latexminted_version}.tar.gz:minted \
                    latexminted-${latexminted_version}-py3-none-any.whl:latexminted

checksums-append    v0.7.1.tar.gz \
                    rmd160  2412432790b4868af8b5bbd9413b107502fd2c0a \
                    sha256  3355bc7608d6191cb304111733304b54a15a5e23b152d4872aca477ffce05952 \
                    size    638532

checksums-append    latexminted-0.7.1-py3-none-any.whl \
                    rmd160  aa44ab1c077a0008999490ded07c7f16230b0171 \
                    sha256  30d49c11bfef387eb9365bc81edff3fbb4f9da49a5ae3b79ace179577f060e15 \
                    size    36604

post-extract {
    system -W ${workpath} "/usr/bin/tar -xzf [shellescape ${distpath}/v${latexminted_version}.tar.gz]"
    set minted_source ${workpath}/minted-python-v${latexminted_version}
    set minted_scripts ${worksrcpath}/runfiles/texmf-dist/scripts/minted

    delete ${minted_scripts}/latexminted-0.6.0-py3-none-any.whl
    copy -force ${distpath}/latexminted-${latexminted_version}-py3-none-any.whl ${minted_scripts}
    copy -force ${minted_source}/latex/restricted/latexminted.py ${minted_scripts}
    reinplace "s/latexminted-0.6.0-py3-none-any.whl/latexminted-${latexminted_version}-py3-none-any.whl/" \
        ${worksrcpath}/tlpkginfo/runfiles
    foreach filename {minted.sty minted1.sty minted2.sty} {
        copy -force ${minted_source}/latex/minted/${filename} \
            ${worksrcpath}/runfiles/texmf-dist/tex/latex/minted/${filename}
    }

    if {[variant_isset doc]} {
        set minted_doc ${worksrcpath}/docfiles/texmf-dist/doc/latex/minted
        foreach filename {DEPENDS.txt README minted.pdf} {
            copy -force ${minted_source}/latex/minted/${filename} ${minted_doc}/${filename}
        }
        copy -force ${minted_source}/latex/CHANGELOG_MINTED_LATEX_PACKAGE.md ${minted_doc}
        copy -force ${minted_source}/python/CHANGELOG_LATEXMINTED_PYTHON_PACKAGE.md ${minted_doc}
        copy -force ${minted_source}/python/latexminted.1 \
            ${worksrcpath}/docfiles/texmf-dist/doc/man/man1/latexminted.1
    }
    if {[variant_isset src]} {
        foreach filename {minted.dtx minted.ins} {
            copy -force ${minted_source}/latex/minted/${filename} \
                ${worksrcpath}/srcfiles/texmf-dist/source/latex/minted/${filename}
        }
    }
}
