
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
@unified-latex/unified-latex-to-hast
Advanced tools
Convert a unified-latex AST to a HAST AST (for HTML conversion)
Functions to convert unified-latex
Abstract Syntax Tree (AST) to a HAST (html-like)
tree.
If you want to convert LaTeX to HTML.
This plugin comes with presets for several common LaTeX macros/environments, but you probably want to
control how various macros evaluate yourself. For example, you may have used \includegraphics
with pdf
s
in your LaTeX source by want to output HTML that manipulates the path and includes png
s instead.
You can accomplish this by passing macroReplacements
(for environments, there is the similarly-named
environmentReplacements
) to the plugin.
For example,
import { unified } from "unified";
import rehypeStringify from "rehype-stringify";
import { htmlLike } from "@unified-latex/unified-latex-util-html-like";
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";
import { unifiedLatexToHast } from "@unified-latex/unified-latex-to-hast";
import { unifiedLatexFromString } from "@unified-latex/unified-latex-util-parse";
import { getArgsContent } from "@unified-latex/unified-latex-util-arguments";
const convert = (value) =>
unified()
.use(unifiedLatexFromString)
.use(unifiedLatexToHast, {
macroReplacements: {
includegraphics: (node) => {
const args = getArgsContent(node);
const path = printRaw(
args[args.length - 1] || []
).replace(/\.pdf$/, ".png");
return htmlLike({
tag: "img",
attributes: { src: path },
});
},
},
})
.use(rehypeStringify)
.processSync(value).value;
console.log(convert(`\\includegraphics{foo.pdf}`));
macroReplacements
and environmentReplacements
functions can return any unified-latex Node
, but
using the htmlLike
utility function will return nodes that get converted to specific HTML. See htmlLike
's
documentation for more details.
npm install @unified-latex/unified-latex-to-hast
This package contains both esm and commonjs exports. To explicitly access the esm export,
import the .js
file. To explicitly access the commonjs export, import the .cjs
file.
unifiedLatexToHast
Unified plugin to convert a unified-latex
AST into a hast
AST.
unified().use(unifiedLatexToHast[, options])
PluginOptions
Plugin<PluginOptions[], Ast.Root, Hast.Root>
function unifiedLatexToHast(
options: PluginOptions
): (tree: Ast.Root, file: VFile) => Hast.Root;
unifiedLatexWrapPars
Unified plugin to wrap paragraphs in \html-tag:p{...}
macros.
Because -
and :
cannot occur in regular macros, there is no risk of
a conflict.
unified().use(unifiedLatexWrapPars[, options])
PluginOptions
Plugin<PluginOptions[], Ast.Root, Ast.Root>
function unifiedLatexWrapPars(options: PluginOptions): (tree: Ast.Root) => void;
attachNeededRenderInfo(ast)
Attach renderInfo
needed for converting some macros into their
katex equivalents.
function attachNeededRenderInfo(ast: Ast.Ast): void;
Parameters
Param | Type |
---|---|
ast | Ast.Ast |
convertToHtml(tree, options)
Convert the unified-latex
AST tree
into an HTML string. If you need
more precise control or further processing, consider using unified
directly with the unifiedLatexToHast
plugin.
For example,
unified()
.use(unifiedLatexFromString)
.use(unifiedLatexToHast)
.use(rehypeStringify)
.processSync("\\LaTeX to convert")
function convertToHtml(
tree: Ast.Node | Ast.Node[],
options: PluginOptions
): string;
Parameters
Param | Type |
---|---|
tree | Ast.Node | Ast.Node[] |
options | PluginOptions |
wrapPars(nodes, options)
Wrap paragraphs in <p>...</p>
tags.
Paragraphs are inserted at
macrosThatBreakPars
environmentsThatDontBreakPars
function wrapPars(
nodes: Ast.Node[],
options: {
macrosThatBreakPars?: string[];
environmentsThatDontBreakPars?: string[];
}
): Ast.Node[];
Parameters
Param | Type |
---|---|
nodes | Ast.Node[] |
options | Omitted |
Name | Type |
---|---|
KATEX_SUPPORT | { macros: any; environments: any; } |
katexSpecificEnvironmentReplacements | Record<string, (node: Ast.Environment) => Ast.Node | Ast.Node[]> |
katexSpecificMacroReplacements | Record<string, (node: Ast.Macro) => Ast.Node | Ast.Node[]> |
PluginOptions
export type PluginOptions = HtmlLikePluginOptions & {
/**
* By default, `unifiedLatexToHast` will force the output to be valid HTML.
* This is accomplished by running `rehypeRaw` on the output which will ensure
* there are no nested `<p>` tags, and that block elements don't end up as children of `<span>`s,
* etc. Set to `true` to skip this check.
*/
skipHtmlValidation?: boolean;
};
v1.8.3
\ref
in PreTeXt conversion\verb
, \textsuperscript
, \textsubscript
, \sout
, and \" i
in HTML conversionFAQs
Convert a unified-latex AST to a HAST AST (for HTML conversion)
The npm package @unified-latex/unified-latex-to-hast receives a total of 44 weekly downloads. As such, @unified-latex/unified-latex-to-hast popularity was classified as not popular.
We found that @unified-latex/unified-latex-to-hast demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.