Closed TMueller83 closed 5 years ago
@dimpase, yes it takes care of %
. This is done by line.split('%')[0]
which first splits line
at each occurrence of %
and then returns the fraction of line
before the first occurence of %
. The check for \usepackage{sagetex}
is then performed on the part of line
before the first %
, i.e. the uncommented part of line
. This makes it possible to detect if \usepackage{sagetex}
is commented out even if there are leading blanks such as in ␣␣%\usepackage{sagetex}
. This is where the original implementation would fail.
but it should ignore ‘ \%’ combinations, as they are not indicating starting points of comments, no?
On Wed, 4 Sep 2019 at 18:49, TMueller83 notifications@github.com wrote:
@dimpase https://github.com/dimpase, yes it takes care of %. This is done by line.split('%')[0] which first splits line at each occurrence of % and then returns the fraction of line before the first occurence of %. The check for \usepackage{sagetex} is then performed on the part of line before the first %, i.e. the uncommented part of each line. This makes it possible to detect if \usepackage{sagetex} is commented out even if there are leading blanks such as in ␣␣%\usepackage{sagetex}. This is where the original implementation would fail.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sagemath/sagetex/pull/36?email_source=notifications&email_token=AAJXYHD75OUIRPDPNJIRKZ3QH7YKBA5CNFSM4HXAO7GKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD54M4NA#issuecomment-528010804, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJXYHFNOF6SAVEQJYCVVXLQH7YKBANCNFSM4HXAO7GA .
What do you mean? Everything following a %
is a comment no matter how many %
follow after.
EDIT: Ah I see, you meant \%
which typesets as a literal % sign? No my code will not work if there is a \%
in the same line as the \usepackage{sagetex}
, since my code regards everything after a %
as comment. But \usepackage{sagetex}
is in the preamble anyway and what is the point of a \%
in the preamble? Maybe a line like
\newcommand{\pct}{\%} \usepackage{sagetex}
This would brake my code, but such a line is orders of magnitude less likely than a line like ␣␣%\usepackage{sagetex}
.
no, TeX will merrily type % if it is escaped by a backslash, and keep going.
On Wed, 4 Sep 2019 at 21:02, TMueller83 notifications@github.com wrote:
What do you mean? Everything following a % is a comment no matter how many % follow after.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sagemath/sagetex/pull/36?email_source=notifications&email_token=AAJXYHFIA6NOEYD635MRDZLQIAH6RA5CNFSM4HXAO7GKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD54ZP2A#issuecomment-528062440, or mute the thread https://github.com/notifications/unsubscribe-auth/AAJXYHCD7IUGPZ3M2LOEGTDQIAH6RANCNFSM4HXAO7GA .
@dimpase, yes I have overlooked the backslash at first. See the edit of my previous comment.
One can actually fix the \%
problem by
line.replace(r'\%', '').split('%')[0]
This first removes all occurrences of \%
from line
and then splits it at each remaining occurrence of %
.
By the way: All these operations do of course not make any changes in the actual TeX file. They only change the python-string line
which python has read from the current line in the TeX file.
Thanks!
Improve the test if '\usepackage{sagetex}' is commented out in the LaTeX source file. See #33.