-
Notifications
You must be signed in to change notification settings - Fork 0
Generic markdown #2
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to look over and test the Python md2tex compiler. Wondering if it's worth it to give it unit tests...
|
||
## Run the Markdown-to-TeX compiler | ||
instructions on how to actually run the compiler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@EvanMPutnam Can you add usage instructions to the readme? I would like to test the md2tex compiler but I'm not sure how
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to update this in a seperate PR when we have the cross platform stuff in place.
REM This is where you specify the path of your document. | ||
set DOCUMENT_PATH="markdown_template.md" | ||
set DOCUMENT_PATH="Templates\\markdown_template.md" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these be arguments instead? or maybe a config file?
@@ -1,12 +1,17 @@ | |||
@echo OFF |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
an equivalent shell script should be created in order to run this in non-windows environments (for example, I use .sh
scripts with Windows Subsystem for Linux and almost never touch Powershell)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to do this in a separate cross-platform branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a chance to look at the code. Looks good but it's breaking on dumb Windows idiosyncrasies. I think you should take a look at how you modify strings as well, directly operating on them with +
or +=
is fragile.
# Possible regex for removing comments. | ||
TEMPLATE_FILE = "spex_template.tex" | ||
#Possible regex for removing comments. | ||
TEMPLATE_FILE = "Templates\\PDD_Template.tex" | ||
COMPILER = ".\\Compile_Scripts\\MikTexCompiler.bat" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These strings are formatted for windows paths. Mac and Linux prefer /paths/like/this
. I think you can get Python to do this on its own using os.path.join
. (https://stackoverflow.com/questions/16010992/how-to-use-directory-separator-in-both-linux-and-windows-in-python)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix in the cross-platform branch
"tex_file": ".\\" + tex_path | ||
}) | ||
#folder that file exists in. It compiles twice to fix fairly common issues with broken references in .aux file. | ||
for i in range(0, 2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than having the compile function loop 3 times, I think it makes more sense to remove the loop here and in the __main__
function call latex.compile
three times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its only twice, non inclusive, however yeah good call. That syntax is a bit dense for what it is actually doing haha.
for txt in sections["ABSTRACT"]["text"].split("\n"): | ||
if txt.strip() == "": | ||
continue | ||
abstract_str += txt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had issues in the past attempting to use math operators to manipulate strings. A drop-in replacement for +=
would be
abstract_str += txt | |
abstract_str.append(txt) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its just shorthand for string concatenation. I personally am not a fan of the append syntax outside of the context of arrays. The efficiency difference is also largely negligible for strings of this length.
Markdown_to_TeX/markdown_compile.py
Outdated
if self.verbose: | ||
#Output complete LaTeX document. | ||
print("") | ||
print(tex_contents) | ||
logging.debug(tex_contents) | ||
|
||
|
||
#Get rid of directory so we can regenerate the new .tex file. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 298 (sorry, GitHub won't let me reference that line directly) is breaking on Windows Subsystem for Linux. WSL uses Unix style paths like/this/
but Windows prefers paths\\like\\this
.
$ python Markdown_to_TeX/markdown_compile.py ./Markdown_to_TeX/Templates/markdown_template.md -t ./Markdown_to_TeX/Templates/PDD_Template.tex
Traceback (most recent call last):
File "Markdown_to_TeX/markdown_compile.py", line 365, in <module>
tex_path = latex.convert()
File "Markdown_to_TeX/markdown_compile.py", line 299, in convert
with open(tex_path, "w") as fle:
FileNotFoundError: [Errno 2] No such file or directory: './Markdown_to_TeX/Templates/markdown_template\\./Markdown_to_TeX/Templates/markdown_template.tex'
A solution to this is using os.path.join()
instead of math operators on this string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to cover that in a cross platform branch.
Updating the python file to take generic tags in the metadata. The user defines them how they wish and then inserts them in the document to be replaced. I also re-arranged the templates into a template folder because of the new generic nature of the md compiler.