{"action":"created","comment":{"url":"https://api.github.com/repos/Khan/KaTeX/pulls/comments/68477403","id":68477403,"diff_hunk":"@@ -137,31 +142,25 @@ Parser.prototype.parseExpression = function(breakOnInfix, breakOnToken) {\n     // we reached the end, a }, or a \\right)\n     while (true) {\n         var lex = this.nextToken;\n-        var pos = this.pos;\n         if (endOfExpression.indexOf(lex.text) !== -1) {\n             break;\n         }\n         if (breakOnToken && lex.text === breakOnToken) {","path":"src/Parser.js","position":74,"original_position":74,"commit_id":"e3dda607afd87a8e6b62fc4135a8f4d50cbee697","original_commit_id":"e3dda607afd87a8e6b62fc4135a8f4d50cbee697","user":{"login":"gagern","id":190759,"avatar_url":"https://avatars.githubusercontent.com/u/190759?v=3","gravatar_id":"","url":"https://api.github.com/users/gagern","html_url":"https://github.com/gagern","followers_url":"https://api.github.com/users/gagern/followers","following_url":"https://api.github.com/users/gagern/following{/other_user}","gists_url":"https://api.github.com/users/gagern/gists{/gist_id}","starred_url":"https://api.github.com/users/gagern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gagern/subscriptions","organizations_url":"https://api.github.com/users/gagern/orgs","repos_url":"https://api.github.com/users/gagern/repos","events_url":"https://api.github.com/users/gagern/events{/privacy}","received_events_url":"https://api.github.com/users/gagern/received_events","type":"User","site_admin":false},"body":"But we break if the next *token* has the given text. True, currently we only use this for `]` which is a one-char token. But we couldn't break on `\\` but we could break on `\\\\`, so token is more fitting. We could use `breakOnTokenText` to distinguish this from the token class, if you prefer.","created_at":"2016-06-24T23:46:30Z","updated_at":"2016-06-24T23:46:30Z","html_url":"https://github.com/Khan/KaTeX/pull/493#discussion_r68477403","pull_request_url":"https://api.github.com/repos/Khan/KaTeX/pulls/493","_links":{"self":{"href":"https://api.github.com/repos/Khan/KaTeX/pulls/comments/68477403"},"html":{"href":"https://github.com/Khan/KaTeX/pull/493#discussion_r68477403"},"pull_request":{"href":"https://api.github.com/repos/Khan/KaTeX/pulls/493"}}},"pull_request":{"url":"https://api.github.com/repos/Khan/KaTeX/pulls/493","id":74621584,"html_url":"https://github.com/Khan/KaTeX/pull/493","diff_url":"https://github.com/Khan/KaTeX/pull/493.diff","patch_url":"https://github.com/Khan/KaTeX/pull/493.patch","issue_url":"https://api.github.com/repos/Khan/KaTeX/issues/493","number":493,"state":"open","locked":false,"title":"Allow macro definitions in settings","user":{"login":"gagern","id":190759,"avatar_url":"https://avatars.githubusercontent.com/u/190759?v=3","gravatar_id":"","url":"https://api.github.com/users/gagern","html_url":"https://github.com/gagern","followers_url":"https://api.github.com/users/gagern/followers","following_url":"https://api.github.com/users/gagern/following{/other_user}","gists_url":"https://api.github.com/users/gagern/gists{/gist_id}","starred_url":"https://api.github.com/users/gagern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gagern/subscriptions","organizations_url":"https://api.github.com/users/gagern/orgs","repos_url":"https://api.github.com/users/gagern/repos","events_url":"https://api.github.com/users/gagern/events{/privacy}","received_events_url":"https://api.github.com/users/gagern/received_events","type":"User","site_admin":false},"body":"This is the next step towards macro support in KaTeX. It doesn't do `\\def` or `\\newcommand` yet (as is the ultimate goal of #250), but it allows the user to declare macros as part of their settings:\r\n\r\n```js\r\nkatex.render(\"\\\\exp\\\\foo\", div, {macros: {\"\\\\exp\": \"e^\", \"\\\\foo\": \"23.4x\"}})\r\n```\r\n\r\nis equivalent to rendering `e^23.4x`, including the fact that only the `2` is the exponent here, just as you'd expect from proper TeX behavior. (You can define `\\foo` as `{23.4x}` to fix this possibly unintended but compatible result.)\r\n\r\nA [previous version of this code](https://github.com/gagern/KaTeX/compare/8496a1e40f8dfbfc8dd7d2e7b5096bd5c2b01c02...b81fcb8765bbdb77c0514c566d651a8726dde15f) has been lying around for about one year, during which it was [in active use by the CindyJS project](https://github.com/CindyJS/CindyJS/blob/f4eeb07f07ace58add34f7b4d028da81288e8d58/plugins/katex/src/js/katex-plugin.js#L107-L145). The code was discussed to some extent in https://github.com/Khan/KaTeX/issues/250#issuecomment-119358745, but according to https://github.com/Khan/KaTeX/issues/266#issuecomment-166949076 I had wanted to polish the error reporting into a pull request in its own right, and somehow more important things got in the way and I never got round to finishing that.\r\n\r\nFor this reason, the first commit of this pull request here is tightly coupled with large-scale modifications to how errors are being reported. The changes are just so tightly integrated with code that moves the parsing of special groups from the lexer to the parser that I feel that separating things again would mean a massive amount of work for little benefit. Doing the error reporting changes without the restructuring to the parser means doing error reporting for certain kinds of objects more than once. Conversely, doing the parser rewrite without a change to error reporting would mean work to carry the positions along for all places that require them. So I kindly ask you to review these changes together.\r\n\r\nThe code is fresh out of my rebase. It passes all tests. Many of the tests I modified, particularly those about error reporting, but overall (perhaps with some *very* few exceptions) I think that the quality of the error reporting has improved by this. Apart from passing tests, I'm far from convinced myself that the code is ready for merging in its current form. But I'd like to discuss my concerns, and any concerns you may have, in order to polish the code up to a mergeable form. The concerns I currently have are the following:\r\n\r\n* Are error positions zero-based or one-based? Current code has zero-based internally and in the `position` property of the error object, but one-based in the message string. This felt most consistent with the previous situation, where many errors were underlined off by one.\r\n* Do we still want to pass position information to functions or environments, or should it be enough that groups and tokens will carry position information?\r\n* I left the hierarchy of test cases in `errors-spec.js` unmodified, even when I moved some of the code from the lexer to the parser. Should we adjust the file, even if doing so will make the diff harder to read? Or should we clean this up in a subsequent PR?","created_at":"2016-06-21T14:26:51Z","updated_at":"2016-06-24T23:46:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e48d7b2f0d051356c9f7cca1679295893c525d72","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Khan/KaTeX/pulls/493/commits","review_comments_url":"https://api.github.com/repos/Khan/KaTeX/pulls/493/comments","review_comment_url":"https://api.github.com/repos/Khan/KaTeX/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Khan/KaTeX/issues/493/comments","statuses_url":"https://api.github.com/repos/Khan/KaTeX/statuses/e3dda607afd87a8e6b62fc4135a8f4d50cbee697","head":{"label":"gagern:macros2","ref":"macros2","sha":"e3dda607afd87a8e6b62fc4135a8f4d50cbee697","user":{"login":"gagern","id":190759,"avatar_url":"https://avatars.githubusercontent.com/u/190759?v=3","gravatar_id":"","url":"https://api.github.com/users/gagern","html_url":"https://github.com/gagern","followers_url":"https://api.github.com/users/gagern/followers","following_url":"https://api.github.com/users/gagern/following{/other_user}","gists_url":"https://api.github.com/users/gagern/gists{/gist_id}","starred_url":"https://api.github.com/users/gagern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gagern/subscriptions","organizations_url":"https://api.github.com/users/gagern/orgs","repos_url":"https://api.github.com/users/gagern/repos","events_url":"https://api.github.com/users/gagern/events{/privacy}","received_events_url":"https://api.github.com/users/gagern/received_events","type":"User","site_admin":false},"repo":{"id":37335285,"name":"KaTeX","full_name":"gagern/KaTeX","owner":{"login":"gagern","id":190759,"avatar_url":"https://avatars.githubusercontent.com/u/190759?v=3","gravatar_id":"","url":"https://api.github.com/users/gagern","html_url":"https://github.com/gagern","followers_url":"https://api.github.com/users/gagern/followers","following_url":"https://api.github.com/users/gagern/following{/other_user}","gists_url":"https://api.github.com/users/gagern/gists{/gist_id}","starred_url":"https://api.github.com/users/gagern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gagern/subscriptions","organizations_url":"https://api.github.com/users/gagern/orgs","repos_url":"https://api.github.com/users/gagern/repos","events_url":"https://api.github.com/users/gagern/events{/privacy}","received_events_url":"https://api.github.com/users/gagern/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gagern/KaTeX","description":"Fast math typesetting for the web.","fork":true,"url":"https://api.github.com/repos/gagern/KaTeX","forks_url":"https://api.github.com/repos/gagern/KaTeX/forks","keys_url":"https://api.github.com/repos/gagern/KaTeX/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gagern/KaTeX/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gagern/KaTeX/teams","hooks_url":"https://api.github.com/repos/gagern/KaTeX/hooks","issue_events_url":"https://api.github.com/repos/gagern/KaTeX/issues/events{/number}","events_url":"https://api.github.com/repos/gagern/KaTeX/events","assignees_url":"https://api.github.com/repos/gagern/KaTeX/assignees{/user}","branches_url":"https://api.github.com/repos/gagern/KaTeX/branches{/branch}","tags_url":"https://api.github.com/repos/gagern/KaTeX/tags","blobs_url":"https://api.github.com/repos/gagern/KaTeX/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gagern/KaTeX/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gagern/KaTeX/git/refs{/sha}","trees_url":"https://api.github.com/repos/gagern/KaTeX/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gagern/KaTeX/statuses/{sha}","languages_url":"https://api.github.com/repos/gagern/KaTeX/languages","stargazers_url":"https://api.github.com/repos/gagern/KaTeX/stargazers","contributors_url":"https://api.github.com/repos/gagern/KaTeX/contributors","subscribers_url":"https://api.github.com/repos/gagern/KaTeX/subscribers","subscription_url":"https://api.github.com/repos/gagern/KaTeX/subscription","commits_url":"https://api.github.com/repos/gagern/KaTeX/commits{/sha}","git_commits_url":"https://api.github.com/repos/gagern/KaTeX/git/commits{/sha}","comments_url":"https://api.github.com/repos/gagern/KaTeX/comments{/number}","issue_comment_url":"https://api.github.com/repos/gagern/KaTeX/issues/comments{/number}","contents_url":"https://api.github.com/repos/gagern/KaTeX/contents/{+path}","compare_url":"https://api.github.com/repos/gagern/KaTeX/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gagern/KaTeX/merges","archive_url":"https://api.github.com/repos/gagern/KaTeX/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gagern/KaTeX/downloads","issues_url":"https://api.github.com/repos/gagern/KaTeX/issues{/number}","pulls_url":"https://api.github.com/repos/gagern/KaTeX/pulls{/number}","milestones_url":"https://api.github.com/repos/gagern/KaTeX/milestones{/number}","notifications_url":"https://api.github.com/repos/gagern/KaTeX/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gagern/KaTeX/labels{/name}","releases_url":"https://api.github.com/repos/gagern/KaTeX/releases{/id}","deployments_url":"https://api.github.com/repos/gagern/KaTeX/deployments","created_at":"2015-06-12T17:29:51Z","updated_at":"2015-08-07T12:01:22Z","pushed_at":"2016-06-22T08:53:15Z","git_url":"git://github.com/gagern/KaTeX.git","ssh_url":"git@github.com:gagern/KaTeX.git","clone_url":"https://github.com/gagern/KaTeX.git","svn_url":"https://github.com/gagern/KaTeX","homepage":"http://khan.github.io/KaTeX/","size":24481,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"browserstack"}},"base":{"label":"Khan:master","ref":"master","sha":"b49eee4de70e787e557f4bfd0b787a728dcaae81","user":{"login":"Khan","id":15455,"avatar_url":"https://avatars.githubusercontent.com/u/15455?v=3","gravatar_id":"","url":"https://api.github.com/users/Khan","html_url":"https://github.com/Khan","followers_url":"https://api.github.com/users/Khan/followers","following_url":"https://api.github.com/users/Khan/following{/other_user}","gists_url":"https://api.github.com/users/Khan/gists{/gist_id}","starred_url":"https://api.github.com/users/Khan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Khan/subscriptions","organizations_url":"https://api.github.com/users/Khan/orgs","repos_url":"https://api.github.com/users/Khan/repos","events_url":"https://api.github.com/users/Khan/events{/privacy}","received_events_url":"https://api.github.com/users/Khan/received_events","type":"Organization","site_admin":false},"repo":{"id":11195700,"name":"KaTeX","full_name":"Khan/KaTeX","owner":{"login":"Khan","id":15455,"avatar_url":"https://avatars.githubusercontent.com/u/15455?v=3","gravatar_id":"","url":"https://api.github.com/users/Khan","html_url":"https://github.com/Khan","followers_url":"https://api.github.com/users/Khan/followers","following_url":"https://api.github.com/users/Khan/following{/other_user}","gists_url":"https://api.github.com/users/Khan/gists{/gist_id}","starred_url":"https://api.github.com/users/Khan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Khan/subscriptions","organizations_url":"https://api.github.com/users/Khan/orgs","repos_url":"https://api.github.com/users/Khan/repos","events_url":"https://api.github.com/users/Khan/events{/privacy}","received_events_url":"https://api.github.com/users/Khan/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Khan/KaTeX","description":"Fast math typesetting for the web.","fork":false,"url":"https://api.github.com/repos/Khan/KaTeX","forks_url":"https://api.github.com/repos/Khan/KaTeX/forks","keys_url":"https://api.github.com/repos/Khan/KaTeX/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Khan/KaTeX/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Khan/KaTeX/teams","hooks_url":"https://api.github.com/repos/Khan/KaTeX/hooks","issue_events_url":"https://api.github.com/repos/Khan/KaTeX/issues/events{/number}","events_url":"https://api.github.com/repos/Khan/KaTeX/events","assignees_url":"https://api.github.com/repos/Khan/KaTeX/assignees{/user}","branches_url":"https://api.github.com/repos/Khan/KaTeX/branches{/branch}","tags_url":"https://api.github.com/repos/Khan/KaTeX/tags","blobs_url":"https://api.github.com/repos/Khan/KaTeX/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Khan/KaTeX/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Khan/KaTeX/git/refs{/sha}","trees_url":"https://api.github.com/repos/Khan/KaTeX/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Khan/KaTeX/statuses/{sha}","languages_url":"https://api.github.com/repos/Khan/KaTeX/languages","stargazers_url":"https://api.github.com/repos/Khan/KaTeX/stargazers","contributors_url":"https://api.github.com/repos/Khan/KaTeX/contributors","subscribers_url":"https://api.github.com/repos/Khan/KaTeX/subscribers","subscription_url":"https://api.github.com/repos/Khan/KaTeX/subscription","commits_url":"https://api.github.com/repos/Khan/KaTeX/commits{/sha}","git_commits_url":"https://api.github.com/repos/Khan/KaTeX/git/commits{/sha}","comments_url":"https://api.github.com/repos/Khan/KaTeX/comments{/number}","issue_comment_url":"https://api.github.com/repos/Khan/KaTeX/issues/comments{/number}","contents_url":"https://api.github.com/repos/Khan/KaTeX/contents/{+path}","compare_url":"https://api.github.com/repos/Khan/KaTeX/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Khan/KaTeX/merges","archive_url":"https://api.github.com/repos/Khan/KaTeX/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Khan/KaTeX/downloads","issues_url":"https://api.github.com/repos/Khan/KaTeX/issues{/number}","pulls_url":"https://api.github.com/repos/Khan/KaTeX/pulls{/number}","milestones_url":"https://api.github.com/repos/Khan/KaTeX/milestones{/number}","notifications_url":"https://api.github.com/repos/Khan/KaTeX/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Khan/KaTeX/labels{/name}","releases_url":"https://api.github.com/repos/Khan/KaTeX/releases{/id}","deployments_url":"https://api.github.com/repos/Khan/KaTeX/deployments","created_at":"2013-07-05T09:01:54Z","updated_at":"2016-06-24T07:36:42Z","pushed_at":"2016-06-22T08:53:16Z","git_url":"git://github.com/Khan/KaTeX.git","ssh_url":"git@github.com:Khan/KaTeX.git","clone_url":"https://github.com/Khan/KaTeX.git","svn_url":"https://github.com/Khan/KaTeX","homepage":"https://khan.github.io/KaTeX/","size":14734,"stargazers_count":4678,"watchers_count":4678,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":309,"mirror_url":null,"open_issues_count":131,"forks":309,"open_issues":131,"watchers":4678,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Khan/KaTeX/pulls/493"},"html":{"href":"https://github.com/Khan/KaTeX/pull/493"},"issue":{"href":"https://api.github.com/repos/Khan/KaTeX/issues/493"},"comments":{"href":"https://api.github.com/repos/Khan/KaTeX/issues/493/comments"},"review_comments":{"href":"https://api.github.com/repos/Khan/KaTeX/pulls/493/comments"},"review_comment":{"href":"https://api.github.com/repos/Khan/KaTeX/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Khan/KaTeX/pulls/493/commits"},"statuses":{"href":"https://api.github.com/repos/Khan/KaTeX/statuses/e3dda607afd87a8e6b62fc4135a8f4d50cbee697"}}}}
{"actor":{"display_login":"gagern"}}