Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equation and Tlkz Preview not working on MacOS #962

Closed
nialltc opened this issue Jul 16, 2019 · 10 comments · Fixed by #1901
Closed

Equation and Tlkz Preview not working on MacOS #962

nialltc opened this issue Jul 16, 2019 · 10 comments · Fixed by #1901
Labels
bug Deficiencies in TeXiFy behaviour. macOS Issues specific to macOS (@cl445 or @efrancis may be able to help)

Comments

@nialltc
Copy link

nialltc commented Jul 16, 2019

Type of JetBrains IDE (IntelliJ, PyCharm, etc.) and version

PyCharm 2019.1.3

TeXiFy IDEA version

0.6.6

Inkscape 0.92
pdf2svg 0.2.3
ImageMagick 7.0.8-14

pdflatex: pdfTeX 3.14159265-2.6-1.40.19 (TeX Live 2018), kpathsea version 6.3.0

(All on PATH)

What I did (steps to reproduce)

When I try to preview either and equation or tlkz the preview panel comes up and the code I am trying to preview is recognised but get error

Cannot run program "pdflatex" (in directory "/var/folders/bv/lcxfrzvd4hj344hgy8qjbkz40000gq/T/tmp1660610588382522293.tmp"): error=2, No such file or directory

The directory T exists but I don't see that .tmp file.

Many thanks for great plugin

@nialltc
Copy link
Author

nialltc commented Jul 16, 2019

On MacOS 10.13.6 :)

@PHPirates
Copy link
Collaborator

The temp directory (I think it's a directory which happens to end with .tmp) is deleted also on error, so that's probably why you don't see it.
Can you create directories yourself (and run pdflatex on a test file in there) in /var/folders/bv/... without elevating permissions of some sorts? (I have no idea how a mac works, sorry. And there is no developer for this plugin who has access to a mac) Maybe creating the temp directory failed, and it didn't throw an AccessDeniedException which is the error we check for in case of permissions problems.

@nialltc
Copy link
Author

nialltc commented Jul 27, 2019

I am able to make a tex file and run with pdflatex in var/folders/bv... without changing any permissions.

Is there anything else I can test manually? What other steps are involved?

@PHPirates
Copy link
Collaborator

@nialltc Hm, strange. This preview thing is very unstable. If you happen to be able to run Kotlin, you could run the following small program, which is pretty much exactly what TeXiFy tries to do, and paste the result here. (If you don't know Kotlin but you want to try, it should not be too difficult to run it with IntelliJ, ask for help if needed)

Test program
import java.io.File
import java.io.PrintWriter
import java.nio.file.Paths
import java.util.concurrent.TimeUnit
import javax.imageio.ImageIO

fun main() {

    // Test constants

    val preamble = """
        \pagestyle{empty}

        \usepackage{color}

        \usepackage{amsmath,amsthm,amssymb,amsfonts}
    """.trimIndent()

    val previewCode = "\$\\xi\$"
    val isWindows = false
    val waitTime = 3L

    // Actual code

    fun runCommand(command: String, args: Array<String>, workDirectory: File): String? {

        val executable = Runtime.getRuntime().exec(
            arrayOf(command) + args,
            null,
            workDirectory
        )

        val (stdout, stderr) = executable.inputStream.bufferedReader().use { stdout ->
            executable.errorStream.bufferedReader().use { stderr ->
                Pair(stdout.readText(), stderr.readText())
            }
        }

        executable.waitFor(waitTime, TimeUnit.SECONDS)

        if (executable.exitValue() != 0) {
            println("$command exited with ${executable.exitValue()}\n$stdout\n$stderr")
            return null
        }

        return stdout
    }


    fun inkscapeExecutable(): String {
        var suffix = ""
        if (isWindows) {
            suffix = ".exe"
        }
        return "inkscape$suffix"
    }

    fun pdf2svgExecutable(): String {
        var suffix = ""
        if (isWindows) {
            suffix = ".exe"
        }
        return "pdf2svg$suffix"
    }

    fun runPreview(tempDirectory: File) {

        val tempBasename = Paths.get(tempDirectory.path.toString(), "temp").toString()
        val writer = PrintWriter("$tempBasename.tex", "UTF-8")

        val tmpContent = """\documentclass{article}
$preamble

\begin{document}

$previewCode

\end{document}"""

        writer.println(tmpContent)
        writer.close()

        println("Running latex in " + tempDirectory.path)

        println(
            runCommand(
                "pdflatex",
                arrayOf(
                    "-interaction=nonstopmode",
                    "-halt-on-error",
                    "$tempBasename.tex"
                ),
                tempDirectory
            )
        )

        println("Running pdf2svg...")

        println(
            runCommand(
                pdf2svgExecutable(),
                arrayOf(
                    "$tempBasename.pdf",
                    "$tempBasename.svg"
                ),
                tempDirectory
            )
        )

        println("Running inkscape...")

        runCommand(
            inkscapeExecutable(),
            arrayOf(
                "$tempBasename.svg",
                "--export-area-drawing",
                "--export-dpi", "1000",
                "--export-background", "#FFFFFF",
                "--export-png", "$tempBasename.png"
            ),
            tempDirectory
        ) ?: throw AccessDeniedException(tempDirectory)

        println("Check out the end result in $tempBasename.png")
    }

    try {
        runPreview(createTempDir())
    } catch (e: AccessDeniedException) {
        println("Trying again in user home dir...")
        runPreview(createTempDir(directory = File(System.getProperty("user.home"))))
    }
}

If not, then I don't really know. There could be many things, maybe Apple doesn't like the dot in the directory name, maybe there is a different permissions problem on /var/folders/bv, or maybe TeXiFy tries to use your home directory (although it seems to fail before that), or something even more complicated.

@nialltc
Copy link
Author

nialltc commented Jul 29, 2019

@PHPirates that ran ok and was able to view png and pdf after.

Here is what is returned.

/Library/Java/JavaVirtualMachines/jdk-10.0.1.jdk/Contents/Home/bin/java "-javaagent:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=49843:/Applications/IntelliJ IDEA.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Users/niallcullinane/Documents/KotlinDelete/out/production/KotlinDelete:/Applications/IntelliJ IDEA.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-reflect.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-test.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jdk7.jar:/Applications/IntelliJ IDEA.app/Contents/plugins/Kotlin/kotlinc/lib/kotlin-stdlib-jdk8.jar" MainKt
Running latex in /var/folders/bv/lcxfrzvd4hj344hgy8qjbkz40000gq/T/tmp15470828521672009015.tmp
This is pdfTeX, Version 3.14159265-2.6-1.40.20 (TeX Live 2019) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode

(/var/folders/bv/lcxfrzvd4hj344hgy8qjbkz40000gq/T/tmp15470828521672009015.tmp/t
emp.tex
LaTeX2e <2018-12-01>
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2018/09/03 v1.4i Standard LaTeX document class
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size10.clo))
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/color.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/local/texlive/2019/texmf-dist/tex/latex/graphics-def/pdftex.def))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2019/texmf-dist/tex/latex/amscls/amsthm.sty)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/amssymb.sty
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
No file temp.aux.
(/usr/local/texlive/2019/texmf-dist/tex/context/base/mkii/supp-pdf.mkii
[Loading MPS to PDF converter (version 2006.09.02).]
) (/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2019/texmf-dist/tex/latex/amsfonts/umsb.fd) [1{/usr/local/t
exlive/2019/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./temp.aux) )</usr/
local/texlive/2019/texmf-dist/fonts/type1/public/amsfonts/cm/cmmi10.pfb>
Output written on temp.pdf (1 page, 8500 bytes).
Transcript written on temp.log.

Running pdf2svg...

Running inkscape...
Check out the end result in /var/folders/bv/lcxfrzvd4hj344hgy8qjbkz40000gq/T/tmp15470828521672009015.tmp/temp.png

Process finished with exit code 0

@PHPirates
Copy link
Collaborator

Oh huh, that's strange. But if the problem is not in that code, then where is it? I'm afraid I don't know without actually debugging TeXiFy on your system :/
Are you sure that like restarting and trying again on an equation gives the same error? You get the error in the Latex output message window, right? Is the line you gave all there is, in that window?

Can you also maybe try again with the following version of TeXiFy? Maybe it will show more error information.
TeXiFy-IDEA-0.6.6-nialltc.zip

@PHPirates
Copy link
Collaborator

Please reopen if you have more information as described in the last post.

@mvdbos
Copy link

mvdbos commented Jul 2, 2020

I have the same problem. Could it be that the problem is that it can't find the pdflatex executable, instead of pdflatex not seeing the tmp file?

@PHPirates
Copy link
Collaborator

PHPirates commented Jul 2, 2020

@mvdbos Yes, a couple of weeks ago someone helped me debug the issue (#1103), and it seems to be the issue mentioned in #25 (comment)
I will put the workaround mentioned there in the wiki. (https://github.com/Hannah-Sten/TeXiFy-IDEA/wiki/Preview#using-the-preview-on-macos)

If you know any way in which we could fix this from the plugin, please let us know. We don't have a Mac so we can't reproduce the problem.

@PHPirates PHPirates added the wontfix Issue will be discarded by the development team. label Jul 2, 2020
@PHPirates PHPirates added the macOS Issues specific to macOS (@cl445 or @efrancis may be able to help) label Aug 20, 2020
@cl445
Copy link

cl445 commented May 11, 2021

The preview is still not working with 0.7.7-alpha.1 .

@PHPirates PHPirates added bug Deficiencies in TeXiFy behaviour. and removed wontfix Issue will be discarded by the development team. labels May 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Deficiencies in TeXiFy behaviour. macOS Issues specific to macOS (@cl445 or @efrancis may be able to help)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants