0

I tried to run latexTop() first then latexMiddle() but it does not seem to work however it does not show error message it just does not append latexmiddle into latextop ,I also tried open('name.tex','r') as myfile: text = myfile.read()

def latexTop():
    doc = Document('name')
    doc.append(Command('title', 'title'))
    doc.append(Command('date', NoEscape(r'\today')))
    doc.append(NoEscape(r'\maketitle'))
    doc.generate_tex()
    #doc.generate_pdf('name',clean_tex=False,compiler='pdflatex')

def latexMiddle(doc):
    doc = Document('name')
    section = Section('Matrix tests')
    subsection = Subsection('Array')
    vec = Matrix(a)
    vec_name = VectorName('a')
    math = Math(data=[vec_name, '=', vec])
    subsection.append(math)
    section.append(subsection)
    subsection = Subsection('Matrix')
    vec = Matrix(a, mtype='b')
    vec_name = VectorName('a')
    math = Math(data=[vec_name, '=', vec])
        
    subsection.append(math)
    section.append(subsection)

Vmpful
  • 1
  • 3
  • 1
    always put full error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information. – furas Apr 02 '22 at 03:09
  • I don't see why it should append `latexmiddle` into `latextop` - they are two separated functions which create two separated documents. Besides `latexmiddle` get `doc` as argument - `def latexMiddle(doc):` - but later it create totally new document `doc = Document('name')` - but finally it never use this `doc` to add anythink - so finally `latexmiddle` seems totally useless. – furas Apr 02 '22 at 03:30
  • It kind of work now after delete doc = Document('name'), I got confused, thank you for your suggestion – Vmpful Apr 02 '22 at 03:52

1 Answers1

1

I can't test it but I think there are big mistakes in code.

  1. you have to run latexMiddle() inside latextTop()

    def latexTop():
        doc = Document('name')
        doc.append(Command('title', 'title'))
        doc.append(Command('date', NoEscape(r'\today')))
        doc.append(NoEscape(r'\maketitle'))
    
        latexMiddle(doc)
    
        doc.generate_tex()
        #doc.generate_pdf('name', clean_tex=False, compiler='pdflatex')
    
  2. latexMiddle gets doc but later it creates totally new doc but finally it make nothing with doc - it doesn't append section - so all code is useless.

    def latexMiddle(doc):
        # doc = Document('name') # DON'T create new document
    
        section = Section('Matrix tests')
    
        subsection = Subsection('Array')
        vec = Matrix(a)
        vec_name = VectorName('a')
        math = Math(data=[vec_name, '=', vec])
        subsection.append(math)
        section.append(subsection)
    
        subsection = Subsection('Matrix')
        vec = Matrix(a, mtype='b')
        vec_name = VectorName('a')
        math = Math(data=[vec_name, '=', vec])
        subsection.append(math)
        section.append(subsection)
    
        doc.append(section)  # <--- append to doc 
    

Eventually you should first create doc and later send it to both functions, and finally generate file.

def latexTop(doc):   # <--- get doc
    
    doc.append(Command('title', 'title'))
    doc.append(Command('date', NoEscape(r'\today')))
    doc.append(NoEscape(r'\maketitle'))

def latexMiddle(doc):
    # doc = Document('name') # DON'T create new document
    
    section = Section('Matrix tests')
    
    subsection = Subsection('Array')
    vec = Matrix(a)
    vec_name = VectorName('a')
    math = Math(data=[vec_name, '=', vec])
    subsection.append(math)
    section.append(subsection)
    
    subsection = Subsection('Matrix')
    vec = Matrix(a, mtype='b')
    vec_name = VectorName('a')
    math = Math(data=[vec_name, '=', vec])
    subsection.append(math)
    section.append(subsection)

    doc.append(section)  # <--- append to doc 

#def latexBottom(doc):
#    doc.append( ...something...)

# ---

doc = Document('name')

latexTop(doc) 
latexMiddle(doc)
#latexBottom(doc)
    
doc.generate_tex()
#doc.generate_pdf('name', clean_tex=False, compiler='pdflatex')
furas
  • 134,197
  • 12
  • 106
  • 148