Files
KaTeX/contrib/copy-tex
Ryan Randall fbffdc5fc7 Webpack dev server (#902)
* Initial webpack config. Moving to ES6 modules. Some module cleanup.

* WIP

* WIP

* Removing commented out code.

* Removing old deps.

* Removing the build script (used for testing).

* Working tests.

* Switching to node api over cli.

* Updating per comments. Still need to fix server.js to properly run the selenium tests.

* Cleaning up the config.

* More cleanup.

* Bringing back server.js for selenium tests.

* Bringing back old dependencies.

* Adding back eslint rules for webpack config. Final cleanup for webpack config.

* Pointing to correct pre-existing module versions. Adding some extra logic to server.js to ensure it gets transpiled properly.

* Getting make build to work again. Updating package.json with some shortcut scripts.

* Resolving conflict.

* Reverting back to commonjs modules.

* Removing extra spaces in babelrc
2017-09-26 12:16:35 -06:00
..
2017-09-04 21:17:46 -04:00
2017-09-26 12:16:35 -06:00
2017-09-04 21:17:46 -04:00
2017-09-26 12:16:35 -06:00
2017-09-04 21:17:46 -04:00
2017-09-04 21:17:46 -04:00

Copy-tex extension

This extension modifes the copy/paste behavior in any browser supporting the Clipboard API so that, when selecting and copying whole KaTeX-rendered elements, the text content of the resulting clipboard renders KaTeX elements as their LaTeX source surrounded by specified delimiters. (The HTML content of the resulting clipboard remains the selected HTML content, as it normally would.) The default delimiters are $...$ for inline math and $$...$$ for display math, but you can easy switch them to e.g. \(...\) and \[...\] by modifying copyDelimiters in the source code.

Usage

This extension isn't part of KaTeX proper, so the script should be separately included in the page. It also provides optional custom CSS that defines KaTeX equations as user-select: all so that they get selected all-or-nothing (and thus trigger the good behavior provided by this extension). Without this CSS, partially selected equations will just get the usual HTML copy/paste behavior.

<link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.8.3/contrib/copy-tex.css" rel="stylesheet" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.8.3/contrib/copy-tex.min.js" integrity="sha384-RkgGHBDdR8eyBOoWeZ/vpGg1cOvSAJRflCUDACusAAIVwkwPrOUYykglPeqWakZu" crossorigin="anonymous"></script>

See index.html for an example. (To run this example from a clone of the repository, run make serve in the root KaTeX directory, and then visit http://0.0.0.0:7936/contrib/copy-tex/index.html with your web browser.)

If you want to build your own custom copy handler based on this one, copy the copy-tex.js into your codebase and replace the require statement with require('katex/contrib/copy-tex/katex2tex.js').

Known Issues

This extension has been tested on Chrome, Firefox, Edge, and Safari.

Microsoft Edge does not seem to support text and HTML content in a single clipboard. In this browser, this extension will just put the text content into the clipboard.

Safari copies correctly, but the selection rectangle renders strangely (too big) when interacting with display math (because of the user-select: all CSS).