-
Notifications
You must be signed in to change notification settings - Fork 127
add a latex macro to convert Tex code to <img> tag using dataURI. #207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Updated, and looking forward for your advices. |
|
Some comments from a first read:
|
|
About site-specific preamble. Actually, I had realized that problem when writing the code, as you can see I tried to make preamble page-specific in the code, and I need your advice on where (and probably how) to elegantly configure the preamble in git so that it can be course-specific. About DVI-based, personally I prefer pdflatex over latex, but I not sure whether there are some tools which can convert pdf to image that are more convenient than dvi2png and dvi2svgm, which are included in Texlive-full, without the need to consider how to install across platform. Maybe inkscape or imagemagick? Thank you for all the precious advices. I'll try to improve the snippet. |
|
In fact, my latex compilation setup is somewhat huge, include many packages, custom commands, something like makeatletter, tikz settings, and many external image files. My idea follows:
In this way, I can merge my local latex project into the course, without keeping 2 different versions. P.S., I've been trying these days to find a convenient crossplatform pdf2png/pdf2svg convertor, but failed, and I found this post also complainted about this issue and stay using dvipng and dvisvgm as the solution. Crossplatform is important for me, because I am developing on windows while deploy on linux. Edit: I just find pdf2svg. Will have a test. Result: pdf2svg is generating svg file much huge than dvisvgm, about 3-4 time bigger. Using example here, the pdf2svg generate a svg with size more than 9M, while dvisvgm's is 1.8M. When the svgs are converted to png (with svgexport), the former result in a file with 3.4M, while the latter is less than 900k. I think currently, the best solution is use dvi as base, and convert svg to png if the size of the svg is not acceptable. |
|
Now I think it's better for the latex code in a page independent of external resources, because if those external settings changed, the previously generated images might fail. The best practice is to offer the full document in the page (at least all elements can be assembled in that page). |
|
I now accept that we should use pdf as base to generate the image, as least as an option. From my experience these days, I found it painful in configuring the fonts and character set on the linux server, just for the purpose of displaying Chinese characters. Svg is a beautiful format (although a cons for svg is that it require larger cache), but use pdf to generate svg is hard, at least for now. However, using dvi as base will bring problems in the future. For example, if I want to migrate data from one server to another, I'll have to do the complex configuration again, that will also be a high barrier for new user. My current solution is:
@inducer I need your advice on this, because I am in urgent need to use this feature. As I've already use this feature on my instance, and the pages are growing. I think I need to rewrite some of the code, but before the number page is out of control. For now, I want to determine args/kwargs (required/optional) that I may use in the caller. My current idea is: Required args:
Optional:
Currently, I have only used |
|
UPDATE:
Requirement:
USAGE: Required args:
Optional:
Example is also updated in inducer/relate-sample#4 |
|
UPDATE:
|
| relate_course_tag = 'relate_course_tag' | ||
|
|
||
| @register(Tags.relate_course_tag) | ||
| @register(Tags.relate_course_tag, deploy=True) |
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.
Does this need to be duplicated?
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'm not saying it's wrong, in fact I don't know--the duplication just looks fishy.
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.
You are right. I'll correct it.
|
|
It has been 2 month since last commit, how time flies. Sorry, I'll return to this asap. |
|
Update:
|
edd7547 to
48839a8
Compare
Conflicts: requirements.txt
course/latex/converter.py
Outdated
|
|
||
| try: | ||
| log = get_abstract_latex_log(log) | ||
| _file_write(self.errlog_saving_path, log) |
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.
Risk of race condition.
course/latex/converter.py
Outdated
| )) | ||
|
|
||
| try: | ||
| shutil.copyfile(image_path, self.image_saving_path) |
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.
Risk of race condition.
Conflicts: course/content.py requirements.txt
dzhuang
left a comment
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.
Use MongoDB as storage instead of filesystem, to store converted dataURI, so as to avoid race conditions. Passed mypy test.
course/latex/utils.py
Outdated
|
|
||
| def _file_read(filename): | ||
| '''Read the content of a file and close it properly.''' | ||
| f = file(filename, 'rb') |
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.
not py3 compatible.
ac38dbf to
cb2056e
Compare
d501a29 to
3c0900e
Compare
Requirement:
Texlive-full might contain all.
USAGE:
Optional args:
output_dir: full path or RELATE styled path of the file generated, default a directory named "latex_image" under MEDIA_ROOT.tex_filename: the based filename of the latex, and image as well, if not set, use md5 of the full latex codeimage_format: the output format of the image, only png and svg are available, and svg is the default. If set png, code with tikz/pgf will still using svg.tex_preamble: the preamble other than what is provided in settings or default value in course.latex_utils. In the yml, it's value might be better to be set by using {% set foo %}{% endset %} block and the usetex_premable=fooas argument (same fortex_preamble_extra).tex_preamble_extra: more packages or settings appended to default preamble.overwrite: regenerate image if it exists, default: False(recommended).html_class_extra: extra html class for theimg-responsivealt: alt attribute for theA brief example is provided in inducer/relate-sample#4