Files
KaTeX/contrib/copy-tex/README.md
ylemkimon 5f32b71c85 Use webpack to build files and webpack-dev-server for testing (#1068)
* Create a separate entry point for webpack

Created a webpack entry point for KaTeX, which imports katex.less. As
flow[1] and jest[2] doesn't support CSS modules natively, a separate
entry point is used and it is not flowtyped.

[1] https://gist.github.com/lambdahands/d19e0da96285b749f0ef
[2] https://facebook.github.io/jest/docs/en/webpack.html

* Use webpack to build files

* Made webpack.config.js export valid webpack configuration
* Use:
browserify -> webpack
babelify -> babel-loader
UglifyJS CLI -> UglifyJsPlugin
Less CLI -> less-loader
cleancss -> cssnano in css-loader
build/fonts -> file-loader
* Inline CSS(Less) using style-loader and export them using
ExtractTextPlugin
* Add `watch` npm script calling `webpack --watch`

* Improve local testing(webpack-dev-server)

* Made webpackDevServer export a valid webpack configuration
* Compile Less and inline CSS using less-loader and style-loader
* Instead of copying files serve files from /static and use file-loader
* Remove old server.js and its dependencies

* Use webpack-dev-server in Screenshotter

* Include contrib in webpack-dev-server

+ Moved common configurations to webpack.common.js

* Rename webpackDevServer.js to webpack.dev...

to be consistent, avoid confusion with webpack-dev-server and follow
webpack configuration naming convention.

* Remove unnecessary conditional output.path

* Use map instead of reduce

+ Add comments regarding function arguments

* Remove unnecessary mkdir and clean build/* before build

* Use katex as external dependency instead of global variable in contrib

Fixes #692.

* Unblock codes as they are built as a module

* Update package-lock.json

* Add comments regarding devServer option

* Lint renamed webpack.dev.js

a0d8b33

* Export ES6 module and expose its default export

* Revert "Browserify hotfix (#1057)"

This reverts commit f6b509123b.

* Enables colors on the console when running the dev server in Screenshotter

* Add context to webpack configuration

Allows webpack to be run from other directories

* Move `rm -rf build/*` to npm scripts

* Check dependencies before build

* Move UglifyJsPlugin into config creation

* Let webpack handle ES6 modules

Do not transform modules to commonjs in Babel. However Jest doesn't not
support ES6 modules, so transfrom modules to commonjs when NODE_ENV is
`test`.

* Add documentation on testing in IE 9 and 10 using webpack-dev-server

Changed version range to include IE-compatible version
2018-01-21 19:48:25 -05:00

2.4 KiB

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.9.0-beta/contrib/copy-tex.css" rel="stylesheet" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.9.0-beta/contrib/copy-tex.min.js" integrity="sha384-aSHW4V0LQ8/J0NPECS3O3IatT0GBp374k6fwk+ATnZCD0vVn03lTljdlntffaZyV" crossorigin="anonymous"></script>

See index.html for an example. (To run this example from a clone of the repository, run npm 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').

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).