-
-
Notifications
You must be signed in to change notification settings - Fork 285
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
LaTeXStrings repr with mixed text/math #359
Comments
Aha - is that why the package exists? I'm always confused why we don't just create a macro Anyway, yes your solution sounds good - you should play around with it inside a Pluto notebook, instead of modifying the Pluto source and rebooting everything while you work on it. Let me know if you need help with that |
I guess the other reason why |
Also why can I not do this? equation = L"\sqrt{100}"
md"I am $(equation) years old." This would not be a problem if they used the same underlying type |
Sorry, all of that is not really relevant here |
It's great that it works, but that is way too complex - can you do it in <10 lines? |
We can do it in 3 lines! https://gist.github.com/fonsp/769c9d2c1dce6df0ea7db1ac173c39c8 We just wrap everything in a |
Still needs to be adapted to the |
Here is a shorter regex version of mine. function prep_for_md_2(s::LaTeXString)
s = String(s) # need String to use regex
# determine indices of non-escaped $'s
imath = findall(r"(?<!\\)\$", s) # returns UnitRange of singleton Int64s
# not sure the best way to collect but this works
imath = [el[1] for el in imath]
# math-only case (allowing inner escaped $)
if (s[1] == '$') & (s[end] == '$') & (length(imath) == 2)
return s[begin+1:end-1] # `strip(s, '$')` would remove leading/trailing escaped $ as well
# mixed math/text case
else
# just a check for now
@assert iseven(length(imath))
# build new string
# string substitution/replacement could be better?
snew = ""
for i in 1:2:length(imath)
bt = i == 1 ? 1 : imath[i-1] + 1
et = imath[i] - 1
bm = imath[i] + 1 # don't include $
em = imath[i+1] - 1
snew *= "\\text{$(s[bt:et])}$(s[bm:em])"
end
if imath[end][1] != length(s)
snew *= "\\text{$(s[imath[end]+1:end])}"
end
end
end Edit: This could be used to do get the array of indices in one line: imath = [m.offset for m in eachmatch(r"(?<!\\)\$", s)] |
I appreciate your careful attention, but let's go with the buggy one-liner. |
Does the bug also happen without the |
Removing the Additionally, in a clean HTML file,<!DOCTYPE html>
<html>
<head>
<title>MathJax TeX Test Page</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg-full.js">
</script>
</head>
<body>
$$
\text{
I am $\sqrt{100}$ years old and have \$50 and $e^{i \pi} = -1$. These are more literal dollar signs:\$\$
}
$$
</body>
</html> it happens with the
definitely more elegant/convenient! |
Thanks for the experiment with HTML! What is the difference between |
The main difference seems to be that the |
Ah I remember - we want to load all extensions, see the discussion here: But I wouldn't worry too much about that test case - that particular use of LaTeXStrings might never happen again |
I did some more testing, even the simple example from the LaTeXStrings readme ( Edit: seems that MathJax bug will be fixed in next release 👍 |
Reopened, see #1164 |
The current approach (7b5dd1d), stripping
$
from beginning and end before passing toMarkdown
'sLaTeX
, does not work in the case of mixed text/math-mode, which LaTeXStrings does support.Since it ends up getting rendered with MathJax, one solution would be to wrap the text (non-math) parts with
\text{}
before passing toLaTeX
. If that seems like a good idea, I would be interested in trying to implement it.The text was updated successfully, but these errors were encountered: