Miguel Graterol
Miguel Graterol

Reputation: 11

Compile a .tex file in C#

im making a .bat file to compile a .tex file to pdf, when i run it directly the .bat file it works fine, but when i run it in c# the error "pdflatex: invalid argument" appers

static void ExecuteCommand()
{
    Process p1 = new Process();
    p1.StartInfo.FileName = @"c:\users\miguelangel\documents\visual studio 2013\Projects\PruebaLatex\PruebaLatex\batch.bat";
    p1.StartInfo.Arguments =@"c:\users\miguelangel\documents\visual studio 2013\Projects\PruebaLatex\PruebaLatex\prueba.tex"; 
    p1.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
    p1.StartInfo.RedirectStandardOutput = true;
    p1.StartInfo.UseShellExecute = false;
    try
    {
        p1.Start();

    }
    catch (Exception e)
    { 
        Console.WriteLine(e); 
    }           
}

Please help me :(, i dont know what else to do, this is the .bat file

pdflatex prueba.tex 

pause

Upvotes: 1

Views: 1200

Answers (1)

cup
cup

Reputation: 8267

Since you have spaces in the directory names, you need to enclose them in quotes

p1.StartInfo.FileName = @"\"c:\users\miguelangel\documents\visual studio 2013\Projects\PruebaLatex\PruebaLatex\batch.bat\"";
p1.StartInfo.Arguments =@"\"c:\users\miguelangel\documents\visual studio 2013\Projects\PruebaLatex\PruebaLatex\prueba.tex\""; 

Alternatively change the working directory to c:\users\miguelangel\documents\visual studio 2013\Projects\PruebaLatex\PruebaLatex before running.

Upvotes: 2

Related Questions