title: Text in .write gets cut off
body: <p>I am trying to make a program that will create a LaTex file (.tex) with a preamble in it, and sooner some sections. I have defined my function <em>thepreamble(title,subject)</em> such that the inputs will be created in the string, which is seen below in my code.</p>
  
  <pre><code># -*- coding: utf-8 -*-
  
  import io
  def thepreamble(title, subject):
      global preamble
      preamble = r'''\documentclass[a4paper, 12pt]{extarticle}
  
  \usepackage[T1]{fontenc}
  \usepackage[utf8x]{inputenc}
  \usepackage[english, danish]{babel}
  \usepackage{fancyhdr}
  \usepackage[dvipsnames]{xcolor}
  \usepackage{mathtools}
  \usepackage{graphicx}
  \usepackage{amssymb}
  \usepackage{titlesec}
  \usepackage[left=0.5in, right=0.5in, top=0.8in, bottom=0.8in]{geometry}
  \usepackage{lipsum}
  \usepackage[breaklinks, colorlinks=true,linkcolor=NavyBlue, citecolor=blue, urlcolor=Blue, linktoc=all]{hyperref}
  \usepackage[utf8x]{inputenc}
  \usepackage{titlesec}
  \usepackage{fix-cm}
  \usepackage{titletoc}
  \usepackage{tocloft}
  \usepackage{setspace}
  \usepackage[all]{hypcap}
  \usepackage{tikz, pgfplots}
  \usetikzlibrary{calc}
  \usepackage{tkz-euclide}
  \usetkzobj{all}
  \usetikzlibrary{positioning}
  \usepackage{tikzrput}
  \usetikzlibrary{arrows.meta}
  \usepackage[labelfont=bf]{caption}
  \usepackage[hang, flushmargin]{footmisc}
  \usepackage{footnotebackref}
  
  
  \pagestyle{fancy}
  
  
  \fancyhf{}
  \fancyfoot[R]{\textbf \thepage}
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{2pt}
  \renewcommand{\footrule}{\hbox to\headwidth{\color{NavyBlue}\leaders\hrule height \footrulewidth\hfill}}
  
  \newcommand{\dl}[1]{\underline{\underline{#1}}}
  
  
  
  
  \setcounter{tocdepth}{2}
  \setcounter{secnumdepth}{0}
  \begin{document}
  \begin{titlepage}
  \begin{center}
  \vspace*{30ex}
  {\fontsize{38}{0}\selectfont \bfseries  \fontfamily{put}\selectfont \color{NavyBlue} '''+ str(title)+'''} \\
  [3ex]
  {\fontsize{18}{0}\selectfont \bfseries  \fontfamily{put}\selectfont \color{NavyBlue}  ('''+str(subject)+ ''')}\\
  [14ex]
  { \fontsize{15}{0}\selectfont Casper Juul Lorentzen} \\
  [3ex]
  {\large \scshape 1.z} \\
  [2ex]
  {\large \scshape 2018}\\
  \vspace{\fill}
  \includegraphics[scale=0.45]{C:/LaTeX/Next.png} \\
  [4mm]
  \small{\bfseries Albertslund Gymnasium \&amp; HF} \\
  \end{center}
  \end{titlepage}
  \renewcommand\contentsname{Indhold \vspace{3ex}}
  
  \tableofcontents
  \thispagestyle{empty}
  \newpage
  \setcounter{page}{1}
      '''
      return preamble
  
  
  
  
  def sections(numsec, numsubsec):
      numbers = []
      numbers.extend(numsubsec)
      global tasks
      tasks = []
  
      print("") 
      #Brug prÃ¦fikset 'r' foran unicodes 
      print("")
      for n,i in zip(range(1, numsec+1),range(0,numsec)):
          print("")
          opgaver = "\section{Opgave "+str(n)+"}"
          print(opgaver)
          print("")
          tasks.append(opgaver)
          for x in range(int(numsubsec[i])):
              print("\subsection{}")
              print("")
  
      return tasks
  def runprogram():
      encoding ='utf8'
      titlefile = input("Title (file): ")
      title = input("Title of document: ")
      subject = input("Subject: ")
      numsec = int(input("How many sections? "))
      filename = "C:\\Users\\Casper\\Documents\\LaTeX\\fire.tex"
      while True:
          numsubsec = input("How many subsections?")
          while len(numsubsec) !=numsec:
              print("")
              numsubsec =input("Error; input must be of "+ str(numsec) + " digits ")
          try:
              with io.open(filename.replace('fire.tex',titlefile+".tex"), 'w', encoding=encoding) as f:
                  f.write(unicode_thepreamble(title, subject))
                  f.close()
  
              #sections(numsec, numsubsec)
              break
          except:
              print("Error")
  
  
  
  runprogram()
  </code></pre>
  
  <p>Whenever I run the program, it creates a new .tex file with the name of </p>
  
  <pre><code>titlefile = input("Title (file): ")
  </code></pre>
  
  <p>As you can see, i have defined <em>preamble</em> as a text with unicode characters in it. And when I run the program, it writes almost everything of the preamble string in the tex document, but it cuts some of it off and creates weird symbol, like this:
  <a href="https://i.stack.imgur.com/VlrLg.png" rel="nofollow noreferrer">tex document created</a></p>
  
  <p>I named the title 'stackoverflow' and the subject 'python problem', and that works fine. But what ought to be '\renewcommand' is in the document '     enewcommand'. I do not know how to fix this. I just want precisely what my preamble strings says.</p>