Skip to content
This repository has been archived by the owner on Feb 21, 2023. It is now read-only.

Generic markdown #2

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open

Generic markdown #2

wants to merge 13 commits into from

Conversation

EvanMPutnam
Copy link
Member

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.

Copy link
Member

@runphilrun runphilrun left a 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
Copy link
Member

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

Copy link
Member Author

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"
Copy link
Member

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
Copy link
Member

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)

Copy link
Member Author

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

Copy link
Member

@runphilrun runphilrun left a 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"
Copy link
Member

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)

Copy link
Member Author

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):
Copy link
Member

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

Copy link
Member Author

@EvanMPutnam EvanMPutnam Oct 4, 2019

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
Copy link
Member

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

Suggested change
abstract_str += txt
abstract_str.append(txt)

Copy link
Member Author

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.

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.
Copy link
Member

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

Copy link
Member Author

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants