-
Notifications
You must be signed in to change notification settings - Fork 9
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
Implement QqLaTeXFormatter #2
Comments
I added 'qqlatex' file to the qqmbr directory. There are a few issues that I don't know yet how to resolve:
|
|
P.S. And it is better not to include code as screenshot in bugreports/questions: you can just use markdown to format code properly in the editor. Otherwise it is mostly impossible for example to reproduce your code as I can't copy-paste it. |
Some updates
|
0It is good habit to mention the number of issue in the commit description (like "Related: #2") and/or mentioned commit id in comment on issue (like "see 51c6cec"). Github makes such mentiones hyperlinks and it allow to follow easily what was changed and why. 1Good. See my comment there. 2If you say that something doesn't work, it is a good idea to provide a code sample that shows what do you mean: your settings, input values, actual behaviour and desired behaviour. Currently, I see that formatter = QqLaTeXFormatter()
'label' in formatter.uses_tags()
# False So it will not be parsed in the default settings. If I add it to parser's parser = QqParser(allowed_tags=formatter.uses_tags() | {'label'})
tree = parser.parse(r"""
\h1 Hello \label test
""")
tree.as_list()
# ['_root', '\n', ['h1', 'Hello ', ['label', 'test\n']]]
# looks good here Not if I trying to format it, I have print(formatter.format(tree))
...
/Users/user/prj/qqmbr/qqmbr/qqlatex.py in handle_simple(self, tag)
60 \{{{name}}} \{{{label}}}
61 {content}
---> 62 """.format(name=self.tag_to_latex[tag.name], content=self.format(tag), label = tag.find('label'))
63
64 def handle_begin_end(self, tag):
KeyError: 'label' This is due to fact that you are trying to invoke The fundamental problem here is inconsistency between LaTeX and qqDoc handling of labels. There are two different cases in LaTeX: \section{Some section}\label{some:label} and \begin{theorem}\label{some:label}
Some theorem
\end{theorem} In qqDoc, in both cases So we have to handle this two cases differently. This is what your code in Actually, there are two possibilities:
I leave it to you to decide what is better. 3You can check how this string is parsed by printing the result of parsing. tree = parser.parse(r"""
\paragraph Some text here
More text.
""")
tree.as_list()
# ['_root', '\n', ['paragraph', 'Some text here\nMore text.\n']] So you see that string
So what's the problem here? |
Because
|
Addressed last comment in Implement QqLaTeXFormatter #2
First of all,
is parsed into
so It should be translated to \section{Section two}
Some text So Please, see also my comments on your commit 9248ad8. Multiline code snippets are created with triple backtics, see the docs. |
Most of your comments are resolved in commit 0361785
is now translated to
This is true that the preceding code is parsed into |
Indeed, why do you need return """
\{name}{caption} {label}
{content}
""".format(name=self.tag_to_latex[tag.name], content=self.format(tag),
label = label_string, caption = caption_string) You have a tag like
It have to be translated to
So the whole content of a tag should go inside a curl brackets in |
Btw, I added testcase related to an issue we discussed. We have to create a testcase for every piece of behaviour we need and then make the program to pass them all (it's called test-driven programming). After that if we make any change to the program we can check if it breaks something or not. You can look at the other tests is Please, if you see that something does not work as expected in your code, add a test that shows how it should work first, then it is easier to discuss it, find a particular place in the program that doesn't work (using debugger) and so on. |
Ok-ok! I see my mistake: I thought that
should be translated to
But I see now that you don't use tabs after
In the commit 8c772f0 I resolved this issue for About cross-referencing: just to clarify, Also, I don't know how to create tests, test, or debug... |
This is why tests are essential — code is better than descriptions. To add a test, just add some functions to the corresponding files in We can begin with |
See this 6577e99 commit
Any idea?
|
Hmm, seem to be a parser bug. I'll dig into it. |
Implement simple qqDoc → LaTeX formatter.
The text was updated successfully, but these errors were encountered: