--- Portfile-0.8.1	2016-06-30 18:38:58.626459446 -0400
+++ Portfile	2016-06-30 18:34:14.325468175 -0400
@@ -60,43 +60,94 @@
 # - it can install its own style files for use within tex/latex
 # We could simply depend on texlive, but some folks prefer MacTeX
 # and object to 2nd multi-GB download!  So we define variants.
+options latexml.found_tex
+default latexml.found_tex no
 
-notes "${name} works best with some version of TeX installed. \
-   Please consider +texlive variant, or PRE-install MacTeX and use +mactex variant."
-
-# The texlive variant depends on texlive
-# and install latexml's stylefiles to texlive's texmf
-variant texlive conflicts mactex description {Build with (macports) texlive support} {
-    notes "Using texlive for TeX: will install styles to its texmf"
-    depends_lib-append      port:texlive
-    pre-configure {
-        configure.args-append   TEXMF=${texlive_texmfports}
+# No texmf install via Makefile.
+pre-configure {
+   configure.args-append   TEXMF=
+  }
+# We don't want dependencies on texlive, but want to cooperate.
+# We'll install style files where texlive expects or will expect.
+post-destroot {
+    xinstall -d ${texlive_texmfdist}/tex/latex/latexml
+    foreach sty [glob ${worksrcpath}/lib/LaTeXML/texmf/*.sty] {
+        file copy -force ${sty} ${texlive_texmfdist}/tex/latex/latexml/
     }
-    post-activate {
-        texlive.mktexlsr
+}
+# invoke mktexlsr IFF texlive already installed;
+# otherwise texlive will do it if it's ever installed.
+post-activate {
+    if [file executable ${prefix}/bin/mktexlsr] {
+        latexml.found_tex yes
+        ${texlive.mktexlsr}
+    }
+}
+# Remove style files
+post-uninstall {
+    foreach sty [glob -nocomplain ${texlive_texmfdist}/tex/latex/latexml/*.sty] {
+        delete ${sty}
+    }
+    if [file executable ${prefix}/bin/mktexlsr] {
+        ${texlive.mktexlsr}
     }
 }
 
 # The mactex variant expects MacTeX to be installed
-# and installs latexml's stylefiles to MacTeX's texmf
-variant mactex conflicts texlive description {Build with MacTeX support} {
-    # check if MacTeX actually seems to be there...
-    pre-configure {
-        if {![file executable /usr/texbin/kpsewhich]} {
-            ui_error "I cannot find MacTeX's kpswhich in /usr/texbin; aborting installation"
-            return -code error "MacTeX not installed"
-        } else {
-            configure.args-append   TEXMF=[exec /usr/texbin/kpsewhich --expand-var='\$TEXMFLOCAL']
+# and installs latexml's stylefiles to MacTeX's texmf (local)
+options latexml.mactex_bin
+options latexml.mactex_texmf
+default latexml.mactex_bin ""
+default latexml.mactex_texmf ""
+set latexml.mactex_candidates { \
+   "/Library/TeX/texbin" \
+   "/usr/texbin" \
+}
+variant mactex description {Build with MacTeX support} {
+    # First, check if MacTeX actually seems to be there...
+    foreach dir ${latexml.mactex_candidates} {
+        if [file executable "${dir}/kpsewhich"] {
+            latexml.mactex_bin ${dir}
+            break
         }
     }
-    notes "Using MacTeX for TeX: will install styles to MacTeX's texmf \
-        (outside macport's common directory structure)"
-    post-activate {
-        system /usr/texbin/mktexlsr
+    if { ${latexml.mactex_bin} != "" } {
+        latexml.mactex_texmf \
+            [exec ${latexml.mactex_bin}/kpsewhich --expand-var='\$TEXMFLOCAL']
+        regsub -all {'} ${latexml.mactex_texmf} "" latexml.mactex_texmf
+        latexml.found_tex yes
+    } else {
+        return -code error "Cannot find MacTeX installation; aborting"
     }
 
+    post-destroot {
+        xinstall -d ${latexml.mactex_texmf}/tex/latex/latexml
+        foreach sty [glob ${worksrcpath}/lib/LaTeXML/texmf/*.sty] {
+            file copy -force ${sty} ${latexml.mactex_texmf}/tex/latex/latexml/
+        }
+    }
+    post-activate {
+        system "${latexml.mactex_bin}/mktexlsr"
+    }
+    # Remove style files
+    post-uninstall {
+        foreach sty [glob -nocomplain ${latexml.mactex_texmf}/tex/latex/latexml/*.sty] {
+            delete ${sty}
+        }
+        system "${latexml.mactex_bin}/mktexlsr"
+    }
+    notes "Using MacTeX for TeX: will install styles to MacTeX's texmf-local \
+        ${latexml.mactex_texmf} \
+        (which is outside macport's common directory structure)"
     # AND, since we're installing files outside macports' normal directories
     destroot.violate_mtree  yes
 }
 
+post-activate {
+    if {! ${latexml.found_tex}} {
+        ui_msg "${name} works best with some version of TeX installed. \
+    Please consider installing texlive, or PRE-install MacTeX and use +mactex variant."
+    }
+}
+
 #============================================================
