1

Scenario

I am compiling a latex document from python 3.6 in Anaconda 4.8.2 on a Windows 10 Pro N device. To do so, I created a python 3.6 environment in Anaconda Prompt, installed miktex in anaconda with command:

conda install -c conda-forge miktex

And execute the following python code with self.create_pdf('test/main.tex','test/main.pdf'):

def create_pdf(self, input_filename, output_filename):
        process = subprocess.Popen([
            'latex',   # Or maybe 'C:\\Program Files\\MikTex\\miktex\\bin\\latex.exe
            '-output-format=pdf',
            '-job-name=' + output_filename,
            input_filename])
        process.wait()        

The latex in question uses, among others, package \usepackage{qrcode}. This causes the python script to manually prompt permission to install the packages as shown in the image below.

enter image description here

Question

How can I compile the latex silently by automatically installing all required packages?

Attempts

In accordance with the latex --help documentiation, I tried running the Anaconda prompt as administrator and passing the -enable-installer. I verified that the manual command latex -output-format=pdf -job-name="test/main.pdf" "test/main.tex" -enable-installer skips the request for permission. Hence, I tried to pass the -enable-installer at the very end with code:

def create_pdf(self, input_filename, output_filename):
    string = f'latex -output-format=pdf -job-name="{input_filename}" "{output_filename}" -enable-installer'
    process = subprocess.Popen([string])        
    process.wait()        

which still prompts for permission even though copy pasting the string in cmd does not.

  • 1
    I believe the first argument to Popen is supposed to be an array of strings: ['latex','-output-format=pdf',...]. Does that help? TBH, I'm surprised that you don't have that package installed. The usual advice is to install the full TeX bundle, so that you get all the packages and don't need to worry about installing various packages as you go along, because it can be a pain. – Teepeemm Aug 21 at 14:07
1

Thanks to the comment of Teepeemm, a solution is found in the form of:

def create_pdfV2(self, input_filename, output_filename):
        process = subprocess.Popen([
            'latex',   # Or maybe 'C:\\Program Files\\MikTex\\miktex\\bin\\latex.exe
            '-output-format=pdf',
            '-job-name=' + output_filename,
            input_filename,
            '-enable-installer'])

The problems in my attempts were:

  1. In the first attempt I did not pass the -enable-installer argument.
  2. In the attempts including the -enable-installer argument, I had also rewritten the command from list format with a single argument per list element to all the arguments in a single list element. This yielded an invalid command even though the -enable-installer command was included. I did not notice this mistake because I forgot I placed a command before my attempts which generated an error which I attributed to the attempt.

Doubts

  1. I am not sure whether this command uses the latex that is installed on my pc or the latex that I installed in Anaconda.
  2. I do not yet know how install the latex command in anaconda with all packages included as suggested in the comment.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.