From 62c1ff33b7a90a77cc3851c41c1e689b2eac4a16 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Sat, 4 Dec 2021 11:59:52 +0100 Subject: feat: add custom latex Macros (#180) * fix: remove \refs from katex processes * feat: add own latex macros --- components/Sidebar/Note.tsx | 3 ++ components/Sidebar/index.tsx | 3 ++ org-roam-ui.el | 10 +++++- pages/index.tsx | 14 +++++--- util/processOrg.tsx | 84 +++++++++++++++++++++++++------------------- util/uniorg.tsx | 3 ++ 6 files changed, 74 insertions(+), 43 deletions(-) diff --git a/components/Sidebar/Note.tsx b/components/Sidebar/Note.tsx index 62cc8ad..1f864f3 100644 --- a/components/Sidebar/Note.tsx +++ b/components/Sidebar/Note.tsx @@ -20,6 +20,7 @@ export interface NoteProps { openContextMenu: any outline: boolean collapse: boolean + macros?: { [key: string]: string } } export const Note = (props: NoteProps) => { @@ -35,6 +36,7 @@ export const Note = (props: NoteProps) => { openContextMenu, outline, collapse, + macros, } = props const extraStyle = outline ? outlineNoteStyle : viewerNoteStyle @@ -68,6 +70,7 @@ export const Note = (props: NoteProps) => { collapse, nodeById, linksByNodeId, + macros, }} /> { @@ -75,6 +76,7 @@ const Sidebar = (props: SidebarProps) => { setFilter, tagColors, setTagColors, + macros, } = props const { highlightColor } = useContext(ThemeContext) @@ -225,6 +227,7 @@ const Sidebar = (props: SidebarProps) => { outline, setOutline, collapse, + macros, }} /> diff --git a/org-roam-ui.el b/org-roam-ui.el index 61b8ea6..17059fe 100644 --- a/org-roam-ui.el +++ b/org-roam-ui.el @@ -145,6 +145,13 @@ Take ID as string as sole argument." :group 'org-roam-ui :type 'hook) +(defcustom org-roam-ui-latex-macros nil + "Alist of LaTeX macros to be passed to org-roam-ui. +Format as, i.e. with double backslashes for a single backslash: +'((\"\\macro\".\"\\something{#1}\"))" + :group 'org-roam-ui + :type 'alist) + ;; Internal vars (defvar org-roam-ui--ws-current-node nil @@ -577,7 +584,8 @@ from all other links." (data . (("dailyDir" . ,daily-dir) - ("roamDir" . ,org-roam-directory))))))))) + ("roamDir" . ,org-roam-directory) + ("katexMacros" . ,org-roam-ui-latex-macros))))))))) (defun org-roam-ui-sql-to-alist (column-names rows) "Convert sql result to alist for json encoding. diff --git a/pages/index.tsx b/pages/index.tsx index 15d6f2f..5900b9b 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -73,6 +73,11 @@ export type NodeById = { [nodeId: string]: OrgRoamNode | undefined } export type LinksByNodeId = { [nodeId: string]: OrgRoamLink[] | undefined } export type NodesByFile = { [file: string]: OrgRoamNode[] | undefined } export type NodeByCite = { [key: string]: OrgRoamNode | undefined } +export interface EmacsVariables { + roamDir?: string + dailyDir?: string + katexMacros?: { [key: string]: string } +} export type Tags = string[] export type Scope = { nodeIds: string[] @@ -138,7 +143,7 @@ export function GraphPage() { const nodeByCiteRef = useRef({}) const tagsRef = useRef([]) const graphRef = useRef(null) - const variablesRef = useRef<{ [variable: string]: string }>({}) + const variablesRef = useRef({}) const clusterRef = useRef<{ [id: string]: number }>({}) const currentGraphDataRef = useRef({ nodes: [], links: [] }) @@ -426,8 +431,8 @@ export function GraphPage() { case 'graphdata': return updateGraphData(message.data) case 'variables': - console.log(message.data) variablesRef.current = message.data + console.log(message.data) return case 'theme': return setEmacsTheme(['custom', message.data]) @@ -665,6 +670,7 @@ export function GraphPage() { filter, setFilter, }} + macros={variablesRef.current.katexMacros} nodeById={nodeByIdRef.current!} linksByNodeId={linksByNodeIdRef.current!} nodeByCite={nodeByCiteRef.current!} @@ -719,7 +725,7 @@ export interface GraphProps { handleLocal: any mainWindowWidth: number setMainWindowWidth: any - variables: { [variable: string]: string } + variables: EmacsVariables graphRef: any clusterRef: any coloring: typeof initialColoring @@ -1254,9 +1260,7 @@ export const Graph = function (props: GraphProps) { height: windowHeight, backgroundColor: getThemeColor(visuals.backgroundColor, theme), warmupTicks: scope.nodeIds.length === 1 ? 100 : scope.nodeIds.length > 1 ? 20 : 0, - //onZoom: ({ k, x, y }) => setZoom(k), onZoom: ({ k, x, y }) => (scaleRef.current = k), - //nodeLabel: (node) => , nodeColor: (node) => { return getNodeColor(node as OrgRoamNode, theme) }, diff --git a/util/processOrg.tsx b/util/processOrg.tsx index 26d9377..189e980 100644 --- a/util/processOrg.tsx +++ b/util/processOrg.tsx @@ -44,6 +44,7 @@ export interface ProcessedOrgProps { outline: boolean collapse: boolean linksByNodeId: LinksByNodeId + macros?: { [key: string]: string } } export const ProcessedOrg = (props: ProcessedOrgProps) => { @@ -58,9 +59,8 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => { outline, collapse, linksByNodeId, + macros, } = props - console.log(linksByNodeId) - console.log(previewNode) if (!previewNode || !linksByNodeId) { return null } @@ -85,8 +85,6 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => { const linkEntries = Object.entries(nodesInNote) const wikiLinkResolver = (wikiLink: string): string[] => { const entry = linkEntries.find((idNodeArray) => { - console.log(idNodeArray) - console.log(wikiLink) return idNodeArray?.[1]?.title === wikiLink }) const id = entry?.[0] ?? '' @@ -117,43 +115,55 @@ export const ProcessedOrg = (props: ProcessedOrgProps) => { const isMarkdown = previewNode?.file?.slice(-3) === '.md' const baseProcessor = isMarkdown ? mdProcessor : orgProcessor + console.log(macros) const processor = useMemo( () => - baseProcessor.use(katex).use(rehype2react, { - createElement: React.createElement, - // eslint-disable-next-line react/display-name - components: { - a: ({ children, href }) => { - return ( - - {children} - - ) - }, - img: ({ src }) => { - return + baseProcessor + .use(katex, { + trust: (context) => ['\\htmlId', '\\href'].includes(context.command), + macros: { + '\\eqref': '\\href{###1}{(\\text{#1})}', + '\\ref': '\\href{###1}{\\text{#1}}', + '\\label': '\\htmlId{#1}{}', + // '\\weird': '\\textbf{#1}', + ...macros, }, - section: ({ children, className }) => ( -
- {children} -
- ), - p: ({ children }) => { - return

{children as ReactNode}

+ }) + .use(rehype2react, { + createElement: React.createElement, + // eslint-disable-next-line react/display-name + components: { + a: ({ children, href }) => { + return ( + + {children} + + ) + }, + img: ({ src }) => { + return + }, + section: ({ children, className }) => ( +
+ {children} +
+ ), + p: ({ children }) => { + return

{children as ReactNode}

+ }, }, - }, - }), + }), [previewNode?.id], ) diff --git a/util/uniorg.tsx b/util/uniorg.tsx index 7ffd3b8..68f0330 100644 --- a/util/uniorg.tsx +++ b/util/uniorg.tsx @@ -13,6 +13,7 @@ export interface UniOrgProps { outline: boolean collapse: boolean linksByNodeId: LinksByNodeId + macros?: { [key: string]: string } } export const UniOrg = (props: UniOrgProps) => { @@ -26,6 +27,7 @@ export const UniOrg = (props: UniOrgProps) => { outline, collapse, linksByNodeId, + macros, } = props const [previewText, setPreviewText] = useState('') @@ -67,6 +69,7 @@ export const UniOrg = (props: UniOrgProps) => { outline, collapse, linksByNodeId, + macros, }} /> )} -- cgit v1.2.3 From f9a000c1175df4ce95dc5e9516164271db0d6f5c Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Sat, 4 Dec 2021 12:02:12 +0100 Subject: doc: correct toc link to package.el (#176) --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0af9744..5d12b2a 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ - [Changelog](#changelog) - [Installation](#installation) - - [Manually](#manually) + - [Using package.el](#package.el) - [Doom](#doom) - [straight/use-package](#straightuse-package) - [Usage](#usage) @@ -36,7 +36,7 @@ For major new features/bugfixes we will update [changelog](https://github.com/or org-roam-ui requires `org-roam`, `websocket`, `simple-httpd`, `f` and Emacs >= 27 for fast JSON parsing. -### Using package.el +### package.el ``` M-x package-install org-roam-ui @@ -369,9 +369,6 @@ If you are interested in being more closely involved with the project, go [here] We would ❤️ to have you on board! -### Hacktoberfest - -Org-roam-ui is also participating in Hacktoberfest 2021! [Enter Hacktoberfest](https://hacktoberfest.digitalocean.com/), check out the [issues labeled Hacktoberfest](https://github.com/org-roam/org-roam-ui/issues) and get a free (as in beer) t-shirt! (as well as the moral satisfaction of contributing to free software, but hey, t-shirt) ## Donate -- cgit v1.2.3 From 1831dd533f0e45bf7cf2415893208026d3b3d5bc Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Sat, 4 Dec 2021 12:06:42 +0100 Subject: cd: set sponsor minimum --- .github/workflows/cd.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index aa7a220..a421f56 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -57,6 +57,7 @@ jobs: with: token: ${{secrets.PAT}} file: 'README.md' + minimum: 500 - name: '[commit changes]' run: | -- cgit v1.2.3