{"action":"created","issue":{"url":"https://api.github.com/repos/lepture/mistune/issues/72","labels_url":"https://api.github.com/repos/lepture/mistune/issues/72/labels{/name}","comments_url":"https://api.github.com/repos/lepture/mistune/issues/72/comments","events_url":"https://api.github.com/repos/lepture/mistune/issues/72/events","html_url":"https://github.com/lepture/mistune/issues/72","id":107815363,"number":72,"title":"Inline math problem","user":{"login":"f-koehler","id":5512292,"avatar_url":"https://avatars.githubusercontent.com/u/5512292?v=3","gravatar_id":"","url":"https://api.github.com/users/f-koehler","html_url":"https://github.com/f-koehler","followers_url":"https://api.github.com/users/f-koehler/followers","following_url":"https://api.github.com/users/f-koehler/following{/other_user}","gists_url":"https://api.github.com/users/f-koehler/gists{/gist_id}","starred_url":"https://api.github.com/users/f-koehler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/f-koehler/subscriptions","organizations_url":"https://api.github.com/users/f-koehler/orgs","repos_url":"https://api.github.com/users/f-koehler/repos","events_url":"https://api.github.com/users/f-koehler/events{/privacy}","received_events_url":"https://api.github.com/users/f-koehler/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-22T22:28:51Z","updated_at":"2015-09-25T05:11:42Z","closed_at":null,"body":"I am currently trying to hack mistune. I implemented math in a similiar way to IPython and mistune-contrib. I have a problem with inline math (maybe it's just me). I wrote a minimal example that reproduces the issue:\r\n```python\r\nimport mistune\r\nimport re\r\n\r\nclass InlineGrammar(mistune.InlineGrammar):\r\n    math = re.compile(\"^\\$\\$(.+?)\\$\\$\", re.DOTALL)\r\n\r\nclass InlineLexer(mistune.InlineLexer):\r\n    default_rules = [\"math\"] + mistune.InlineLexer.default_rules\r\n\r\n    def __init__(self, renderer, **kwargs):\r\n        rules = InlineGrammar()\r\n        super(InlineLexer, self).__init__(renderer, rules, **kwargs)\r\n    \r\n    def output_math(self, m):\r\n       return self.renderer.inline_math(m.group(1))\r\n\r\nclass Renderer(mistune.Renderer):\r\n    def inline_math(self, text):\r\n        return \"@@%s@@\" % text\r\n\r\nmd = mistune.Markdown(Renderer(), inline=InlineLexer(Renderer()))\r\nprint(md.render(r\"$$\\begin{pmatrix}a \\\\ b\\end{pmatrix}$$\"))\r\nprint(md.render(r\"Just some text $$\\begin{pmatrix}a \\\\ b\\end{pmatrix}$$ around my math\"))\r\n```\r\n\r\nThis code should yield the output\r\n```html\r\n<p>@@\\begin{pmatrix}a \\\\ b\\end{pmatrix}@@</p>\r\n\r\n<p>Just some text @@\\begin{pmatrix}a \\\\ b\\end{pmatrix}@@ around my math</p>\r\n\r\n```\r\nbut results in\r\n```html\r\n<p>@@\\begin{pmatrix}a \\\\ b\\end{pmatrix}@@</p>\r\n\r\n<p>Just some text $$\\begin{pmatrix}a \\ b\\end{pmatrix}$$ around my math</p>\r\n\r\n```\r\nThe problem is that in the second case the regex for inline_math does not match. But I do not know why.\r\n\r\nAny ideas?\r\n\r\nP.S.: I want `$$x$$ -> @@x@@` just to see if the code works. Later I want `$$x$$ -> $$x$$`"},"comment":{"url":"https://api.github.com/repos/lepture/mistune/issues/comments/143128858","html_url":"https://github.com/lepture/mistune/issues/72#issuecomment-143128858","issue_url":"https://api.github.com/repos/lepture/mistune/issues/72","id":143128858,"user":{"login":"lepture","id":290496,"avatar_url":"https://avatars.githubusercontent.com/u/290496?v=3","gravatar_id":"","url":"https://api.github.com/users/lepture","html_url":"https://github.com/lepture","followers_url":"https://api.github.com/users/lepture/followers","following_url":"https://api.github.com/users/lepture/following{/other_user}","gists_url":"https://api.github.com/users/lepture/gists{/gist_id}","starred_url":"https://api.github.com/users/lepture/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lepture/subscriptions","organizations_url":"https://api.github.com/users/lepture/orgs","repos_url":"https://api.github.com/users/lepture/repos","events_url":"https://api.github.com/users/lepture/events{/privacy}","received_events_url":"https://api.github.com/users/lepture/received_events","type":"User","site_admin":false},"created_at":"2015-09-25T05:11:42Z","updated_at":"2015-09-25T05:11:42Z","body":"@f-koehler \r\n\r\n```python\r\nclass InlineGrammar(mistune.InlineGrammar):\r\n    math = re.compile(r'^\\${2}([\\s\\S]+?)\\${2}(?!\\$)')\r\n    text = re.compile(r'^[\\s\\S]+?(?=[\\\\<!\\[_*`~\\$]|https?://| {2,}\\n|$)')\r\n```\r\n\r\nYou should also modify regex pattern for text."}}