Skip to content

Instantly share code, notes, and snippets.

@the-admax
Last active January 22, 2022 09:30
Show Gist options
  • Select an option

  • Save the-admax/98f82f2786831043b157ae82287b0562 to your computer and use it in GitHub Desktop.

Select an option

Save the-admax/98f82f2786831043b157ae82287b0562 to your computer and use it in GitHub Desktop.
YouTrack MathJax (lame patch v1.1)
<!-- KaTex support -->
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"></script>
<script type="text/javascript">
function onMarkupCompleted($element) {
var root = ($element != null? $element : document);
angular.forEach(root.querySelectorAll(".yt-wiki"), function(el) {
if (window.MathJax) {
MathJax.tex2jax = Object.assign(MathJax.tex2jax || {}, {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true,
});
MathJax.Hub.Queue(["Typeset", MathJax.Hub, el]);
} else if (window.renderMathInElement) {
var options = {
delimiters: [
{left: '$$', right: '$$', display: true },
{left: '$', right: '$', display: false },
{left: "\\(", right: "\\)", display: false},
{left: "\\[", right: "\\]", display: true},
],
macros: {
},
};
renderMathInElement(el, options);
}
});
}
angular.module("youtrack.components.markup").config(['$provide', function($provide) {
// TODO There must be a decorator (or some other way) to signal
$provide.decorator('getMarkupPreview', ['$delegate', function($delegate) {
return function() {
return $delegate.apply(null, arguments).then(function(html) {
setTimeout(onMarkupCompleted, 500);
return html;
});
}
}]);
}]);
setInterval(onMarkupCompleted, 10000, null);
</script>
<!-- /KaTex support -->
<script type="text/javascript">
window.MathJax = {
tex2jax: {
inlineMath: [ ['$','$'], ["\\(","\\)"] ],
displayMath: [ ['$$','$$'], ["\\[","\\]"] ],
processEscapes: true
}
};
function onMarkupCompleted($element) {
var root = ($element != null? $element : document);
angular.forEach(root.querySelectorAll(".yt-wiki"), function(el) {
MathJax.Hub.Queue(["Typeset", MathJax.Hub, el]);
});
}
angular.module("youtrack.components.markup").config(['$provide', function($provide) {
// TODO There must be a decorator (or some other way) to signal
$provide.decorator('getMarkupPreview', ['$delegate', function($delegate) {
return function() {
return $delegate.apply(null, arguments).then(function(html) {
setTimeout(onMarkupCompleted, 500);
return html;
});
}
}]);
}]);
setInterval(onMarkupCompleted, 10000, null);
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS_HTML' async></script>

YouTrack MathJax patch

As IntelliJ team has neither plans on integration of LaTeX support into YouTrack, nor gives any evidence of steps to towards it, I've made my own "crutch".

It intercepts invocations of getMarkupPreview used in live preview, and signals MathJax/KaTex to rerender formulas. Static wiki markup rendering bypasses getMarkupPreview, and I haven't figured out yet a better solution than plain setInterval.

Suggestions are welcome!

Manual installation

(assuming the YouTrack 2019+ is installed)

  1. Open ~/.youtrack/app/apps/youtrack/web/static/index.html with your favourite editor;
  2. Put the contents of [katex.html] (preferred) or [mathjax.html] into to it right before the closing <body/> tag.
  3. Restart YouTrack

Note

Updating YouTrack erases these modifications, so the index.html is needed to be patched again after update.

Automated patch-based installation won't work probably, as surrounding lines have random numbers as script names that change from build to build.

Changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment