mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-13 06:58:40 +00:00
* copy-tex: Use JS to select full equation instead of CSS * remove CSS * Update webpack.common.js * more build tweaks * Update contrib/copy-tex/copy-tex.js Co-authored-by: Erik Demaine <edemaine@mit.edu> * Document new behavior BREAKING CHANGE: copy-tex extension no longer has (or requires) a CSS file. * Code cleanup, lint fixes, port to Flow * Rewrite to extend both start and end of range * Remove contrib/**/*.css linting Co-authored-by: Erik Demaine <edemaine@mit.edu>
40 lines
1.9 KiB
Markdown
40 lines
1.9 KiB
Markdown
# Copy-tex extension
|
|
|
|
This extension modifies the copy/paste behavior in any browser supporting the
|
|
[Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/ClipboardEvent)
|
|
so that, when selecting and copying 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](copy-tex.js).
|
|
Note that a selection containing part of a KaTeX formula gets extended to
|
|
include the entire KaTeX formula.
|
|
|
|
## Usage
|
|
|
|
This extension isn't part of KaTeX proper, so the script should be separately
|
|
included in the page.
|
|
|
|
```html
|
|
<script src="https://cdn.jsdelivr.net/npm/katex@0.15.6/dist/contrib/copy-tex.min.js" integrity="sha384-Ep9Es0VCjVn9dFeaN2uQxgGcGmG+pfZ4eBaHxUpxXDORrrVACZVOpywyzvFRGbmv" crossorigin="anonymous"></script>
|
|
```
|
|
|
|
(Note that, as of KaTeX 0.16.0, there is no longer a corresponding CSS file.)
|
|
|
|
See [index.html](index.html) for an example.
|
|
(To run this example from a clone of the repository, run `yarn start`
|
|
in the root KaTeX directory, and then visit
|
|
http://localhost: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')`.
|
|
|
|
ECMAScript module is also available:
|
|
```html
|
|
<script type="module" src="https://cdn.jsdelivr.net/npm/katex@0.15.6/dist/contrib/copy-tex.mjs" integrity="sha384-+gSYJ3yzY30+a6FGYJXOx9swmWs5oPKEi1AeCsAxsLexABlUXgHXkOkEZCj0Lz8U" crossorigin="anonymous"></script>
|
|
```
|