def METHOD_NAME(doc, pdfname):
  latex = subprocess.Popen(['pdflatex', '-jobname={}'.format(pdfname)], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  out, err = latex.communicate(doc)
  if (latex.returncode):
    print(out)
  else:
    print('OK.')