-
Notifications
You must be signed in to change notification settings - Fork 91
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
LaTeX CI Checks #3079
Comments
@tirix - ChkTeX is an interesting idea. My intended idea was to generate some TeX files, then ask TeX generate pdf files & see if that works. We could do both. |
I can provide the code I made if it's useful, there are some issues tho:
In any case I believe this approach is better than writing only a few TeX proofs/statements, since with the latter method you wouldn't check the functionality of all latex definitions. |
Does it also run in GNU Octave? If not, could it be easily converted? GNU Octave is pretty compatible for such things, I've used it for some machine learning work. I agree, a single test that "checks all definitions" makes sense, as long as it doesn't take TOO long. |
I don't use Octave so I'm not sure, I know they are generally similar, but there might be some functions that Matlab has and Octave hasn't, as well as some minor language differences.
My code takes about 10 seconds to generate the list, which isn't super fast, I guess someone with more experience than me could make it more efficient. Let me know if you are interested. It's only 80 lines of code, so I guess I can just share it here. |
10 seconds is fine. Yes, interested. If its only purpose is to test the generated TeX code, the easy solution is to add it to set.mm (say in scripts/), which is also where our CI test code for set.mm is. I don't remember if our base image includes LaTeX. |
Ok, so I runned it again right now with Matlab R2021a 64-bit and it works fine. The following file (collector.txt) is the code, I changed the format to .txt because Github doesn't let me load Matlab files, originally it was 'collector.m', but I don't know if it's the same for Octave. The following is first line of the code, here you write which Metamath database you want to read, you need to have that file in the same folder as "collector.m". I setted it to read 'set.mm':
I downloaded the most recent version of set.mm, and runned the program, this should be the output: The program generates the file in a .tex format, I changed to .txt for the same reason described above. Each line corresponds to one latex substitution. I observed that only one of them Note: even if you remove I already added |
Here is the Matlab code from @GinoGiotto - are you releasing this to the public domain, releasing under MIT license, something else? Code:
|
I would replace amsmath with mathtools in this code (mathtools load amsmath anyway). @GinoGiotto : for log_, use |
To be honest I'm not educated in this field, feel free to do whatever you want with it, I won't complain. |
Ok, I noted it in my list.
Done collector.txt |
I made a small optimization. Originally 'collector.m' cycled through the entire Metamath database, but that's inefficient. I edited so that it cycles through the $t comment only. Now it takes about 3 seconds to run. |
Could it be that a simple
Which outputs something like:
Then we only have to add the prelude/header/footer. |
There are some latexdefs using single quotes, but this should be manageable. Add |
@tirix Your approach looks much better than mine. Does it work for latexdefs spanning over multiple lines? I'm very interested in more efficient TeX collectors. |
Okay, I'm interpreting "do whatever you want with it" as a CC0 dedication: https://creativecommons.org/publicdomain/zero/1.0/ |
I think sed would have trouble with the definitions crossing multiple lines. I'd use awk or python. |
@david-a-wheeler I updated the comments with the CC0 licenced code files. |
The simple pattern above does not work with multiple line, as suggested by @david-a-wheeler we either have to use another tool, or more advanced sed options. |
That PR was moved to metamath/metamath-exe#131 and it has been merged. The preambule now has |
I think I made some progress. I wrote a shorter version of "collector" in Python, runned it with the Python IDLE and it seems to work. I used regular expressions, which aren't really my strong suit, but I think it looks promising, specifically:
The following code prints LaTeX substitutions in the Python shell: # Creative Commons Zero v1.0 Universal # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted. # This code is licensed under CC0 - https://creativecommons.org/publicdomain/zero/1.0/ # Author: Gino Giotto import re with open('set.mm', 'r') as file: text = file.read() pattern = r"latexdef\s+['\"]\S+['\"]\s+as(?P<tex>(?:\s*\n?\s*['\"].+['\"]\s*\+?)+);" matches = re.finditer(pattern, text) i = 0 for match in matches: i = i + 1 tex_part = (match.group("tex")).strip() trimmed = tex_part[1:-1].strip() final = re.sub(r"['\"]\s*\+\n\s*['\"]"," ", trimmed) print("\\\\" + str(i) + " && & " + " " + final) And the following file is the complete code that generates the TeX list in a Metamath proof format: TeX_collector.txt This is the output file: list.txt The only issue is that it probably picks up some commented LaTeX substitutions, so unless there will be improvements, bad latex would be checked in the comments too. |
Looks good! |
Like this? list.txt I'll make the pull request soon. |
Yes, this way we can also see the original token, so this can act like the mmascii page, but for LaTeX. |
Also, you can name your file |
The "tabular" environment is more appropriate than the "align" environment. |
Well, I guess the good news is that we are finding & fixing the problems systematically. Once we fix it, and add tests to keep it fixed, it should stay fixed :-). |
It doesn't work either, it still gives errors for verbatim and it doesn't recognize math formulas. Also in general I would prefer to not change the basic Metamath proof style to have more reliable testing. |
I have not done any LaTeX since too many years to count, so I'm afraid I'm not of good advice here... This StackOverflow answer says you need to declare the column as a paragraph column, have you tried that? The ASCII math token is a better reference than a running index, but if it does not work, but you can drop the |
I missed that, thanks. Yes this solution works for placing I was able to make it work using the \documentclass{article} \usepackage{graphicx} \usepackage{amssymb} \usepackage{mathtools} \usepackage{amsthm} \usepackage{mathrsfs} \begin{document} \begin{enumerate} \item \verb!(! \quad $($ \item \verb!)! \quad $)$ \item \verb!->! \quad $\rightarrow$ \item \verb!&! \quad $\mathrel{\&}$ \item \verb!=>! \quad $\Rightarrow$ \item \verb!-.! \quad $\lnot$ \item \verb!wff! \quad $\mathrm{wff}$ \item \verb!|-! \quad $\vdash$ \item \verb!ph! \quad $\varphi$ \end{enumerate} \end{document} Which produces the output: The only problem is that no token should have a I didn't use This solution has an advantage tho, it's easier to spot malfunctioning latexdefs because in this case TeX editors tell where the errors are. If you like this proposal we could work from here, otherwise I will just make a pull request of my original solution I guess. |
Yes, tabular is merely an environment to write tables, so it does not switch to math mode. You have to write equations as usual by surrounding them with $...$. I'm not sure what your "table cut" problem is, but since the positioning is "floating", pdflatex may have a problem positioning it if it spans more than a page. You can tweak the python code so that every 20 lines, for instance, it adds something like |
I remember having to fight long tables for the Metamath book (which uses TeX). i ended up switching to "longtabu" for big tables. This was a big improvement; the big demo table in appendix A could have words flow in a cell AND nicely split across pages. Headers reappear on each page. Hyperlinks work, and cells can have forced line breaks. This works on both normal size and narrow size. Your mileage may vary, but it may be worrth investigating. Check out metamath-book if you want to see an example. |
My TeX editors had some trouble with LaTeX code: \documentclass{article} \usepackage{graphicx} \usepackage{amssymb} \usepackage{mathtools} \usepackage{amsthm} \usepackage{mathrsfs} \usepackage{longtable} \begin{document} \begin{longtable}{|l|} 1. \quad \verb!(! \quad $($ \\ 2. \quad \verb!)! \quad $)$ \\ 3. \quad \verb!->! \quad $\rightarrow$ \\ 4. \quad \verb!&! \quad $\mathrel{\&}$ \\ 5. \quad \verb!=>! \quad $\Rightarrow$ \\ 6. \quad \verb!-.! \quad $\lnot$ \\ 7. \quad \verb!wff! \quad $\mathrm{wff}$ \\ 8. \quad \verb!|-! \quad $\vdash$ \\ 9. \quad \verb!ph! \quad $\varphi$ \\ 10. \quad \verb!ps! \quad $\psi$ \\ 11. \quad \verb!ch! \quad $\chi$ \\ \end{longtable} \end{document} Output: The width of the table is automatically adjusted depending on the longest latex substitution present in the list. For set.mm it is as wide as in the figure above. |
Now you can make a real table: use |
Yes, LaTeX checks are up and running. |
I think @david-a-wheeler expressed his wishes for testing some latex proofs as well #3100 (comment) #3074 (comment), but I guess it can be addressed on a separate occasion and it would require to fix metamath/metamath-exe#129 first anyway. |
@david-a-wheeler expressed his wish for LaTeX checks in the CI.
@GinoGiotto suggested to use a tool to generate a TeX file listing all definitions. We can't visually check the result but we could then run some checker like e.g.
ChkTeX
to ensure the generared TeX file is semantically valid.The text was updated successfully, but these errors were encountered: