简体   繁体   English

将字符串导出到.tex文件时为空文档

[英]Empty document when export string to .tex file

I am trying to create a simple .tex file: 我正在尝试创建一个简单的.tex文件:

document = """
\documentclass[12pt]{article}
\begin{document}
Hello world!
$Hello world!$ %math mode 
\end{document}
"""

file = open("main.tex",'w')
file.write(document) 
file.close

It creates a document, named "main.tex" but this document is empty. 它创建一个名为“ main.tex”的文档,但该文档为空。 Any ideas why and how to fix it? 任何想法为什么以及如何解决它?

If you run this code like this, the problem come from: 如果您以这种方式运行此代码,则问题来自:

file.close

add parenthensis to: 将括号添加到:

file.close

which become: 变成:

file.close()

you could try this: 您可以尝试以下方法:

Sub Create_Text()

On Error Resume Next
MkDir "C:\Temporal"

On Error GoTo 0

document = "" & _
"\documentclass[12pt]{article}" & _
"\begin{document} " & _
"Hello world! " & _
"$Hello world!$ %math mode " & _
"\end{document}"

Open "C:\Temporal\main.txt" For Append As #1
    Print #1, document & ";"
    Close #1

End Sub

I hope this helps!!! 我希望这有帮助!!!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM