Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add break after \\ macro in text mode #59

Merged
merged 3 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# unified-latex Changelog

### v1.6.0
- Embellishment tokens are now supported in macro `signature`s. E.g., a `xxx: {signature: "e{^_}"}` will allow `\xxx_{foo}^{bar}` and `\xxx^{foo}_{bar}` to parse correctly.
- Stop tokens can now be regular string characters. For example `xxx: {signature: "ua"}` will allow `\xxx YYYaBBB` to consume `YYY` leaving `BBB` unconsumed.
- Break after `\\` macro when pretty printing (Issue #59)
- [DEVELOPMENT] Added `tsconfig.json` files to each `test/` folder for more granular control of the typescript settings.

### v1.5.0
- HTML conversion: `vspace` and `hspace` now give the amount in a `data-amount` attribute.
- HTML conversion: unknown macros now have their arguments wrapped in spans instead of appearing as formatted LaTeX code.
Expand Down
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions packages/test-common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@ expect.extend({
inStr
)}\n\nthe output did ${
pass ? "" : "not"
} format correctly\n\n${this.utils.printDiffOrStringify(
outStr,
formatted,
"Expected",
"Received",
false
)}`,
} format correctly\n\n${this.utils.diff(outStr, formatted)}`,
};
},
});
Expand Down
3 changes: 3 additions & 0 deletions packages/unified-latex-builder/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-cli/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
2 changes: 1 addition & 1 deletion packages/unified-latex-ctan/package/latex2e/provides.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { cleanEnumerateBody } from "../../utils/enumerate";

export const macros: MacroInfoRecord = {
// Special
"\\": { signature: "!s !o" },
"\\": { signature: "!s !o", renderInfo: { breakAfter: true } },
_: { signature: "m", escapeToken: "" },
"^": { signature: "m", escapeToken: "" },
// \newcommand arg signature from https://www.texdev.net/2020/08/19/the-good-the-bad-and-the-ugly-creating-document-commands
Expand Down
3 changes: 3 additions & 0 deletions packages/unified-latex-ctan/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
1 change: 1 addition & 0 deletions packages/unified-latex-ctan/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
},
"include": ["./**/*.ts", "./package/**/*.ts"],
"references": [
{ "path": "../structured-clone" },
{ "path": "../unified-latex-types" },
{ "path": "../unified-latex-builder" },
{ "path": "../unified-latex-util-argspec" },
Expand Down
3 changes: 3 additions & 0 deletions packages/unified-latex-lint/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
12 changes: 10 additions & 2 deletions packages/unified-latex-prettier/tests/formatting-tikz.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { prettierPluginLatex } from "../libs/prettier-plugin-latex";
import "../../test-common";
import * as fs from "node:fs/promises";
import path from "node:path";
import { createRequire } from "module";
const require = createRequire(import.meta.url);

const PACKAGE_ROOT = path.join(
require.resolve("@unified-latex/unified-latex-prettier"),
"..",
".."
);

/* eslint-env jest */
const formatter = async (x: string) =>
Expand Down Expand Up @@ -84,13 +92,13 @@ describe("unified-latex-prettier", () => {
it("prints tikz samples", async () => {
// ts-ignore
const inStr = await fs.readFile(
"./packages/unified-latex-prettier/tests/samples/tikz/unformatted.tex",
path.join(PACKAGE_ROOT, "./tests/samples/tikz/unformatted.tex"),
{
encoding: "utf-8",
}
);
const outStr = await fs.readFile(
"./packages/unified-latex-prettier/tests/samples/tikz/formatted-wide.tex",
path.join(PACKAGE_ROOT, "./tests/samples/tikz/formatted-wide.tex"),
{
encoding: "utf-8",
}
Expand Down
10 changes: 9 additions & 1 deletion packages/unified-latex-prettier/tests/formatting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,15 @@ c
});

it("Double backslash macro doesn't absorb optional argument if there's a space in front (issue #40)", async () => {
const STRINGS = [{ inStr: "\\\\ [2pt]", outStr: "\\\\ [2pt]" }];
const STRINGS = [{ inStr: "\\\\ [2pt]", outStr: "\\\\\n[2pt]" }];

for (const { inStr, outStr } of STRINGS) {
await expect(inStr).toFormatAs(outStr, formatter);
}
});

it("Double backslash forces a newline in text mode (issue #12)", async () => {
const STRINGS = [{ inStr: "a\\\\b", outStr: "a\\\\\nb" }];

for (const { inStr, outStr } of STRINGS) {
await expect(inStr).toFormatAs(outStr, formatter);
Expand Down
3 changes: 3 additions & 0 deletions packages/unified-latex-prettier/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
4 changes: 2 additions & 2 deletions packages/unified-latex-to-hast/tests/convert-to-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ describe("unified-latex-to-hast:convert-to-html", () => {
},
})
.use(rehypeStringify)
.processSync(value).value;
.processSync(value).value as string;

let ast;
let ast: string;

ast = convert(`\\includegraphics{myfile.pdf}`);
expect(normalizeHtml(ast)).toEqual(
Expand Down
3 changes: 3 additions & 0 deletions packages/unified-latex-to-hast/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-to-mdast/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
15 changes: 14 additions & 1 deletion packages/unified-latex-types/libs/info-specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,26 @@ export type MacroInfo = {
* @type {boolean}
*/
pgfkeysArgs?: boolean;
/**
* Whether there should be line breaks after the macro
* (e.g., like the `\\` command.)
*
* @type {boolean}
*/
breakAfter?: boolean;
/**
* Whether there should be line breaks before and after the macro
* (e.g., like the \section{...} command.)
* (e.g., like the `\section{...}` command.)
*
* @type {boolean}
*/
breakAround?: boolean;
/**
* Whether there should be line breaks before the macro.
*
* @type {boolean}
*/
breakBefore?: boolean;
/**
* Whether the contents of the macro should be assumed to be in math mode.
*
Expand Down
3 changes: 3 additions & 0 deletions packages/unified-latex-util-align/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-argspec/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { structuredClone } from "@unified-latex/structured-clone";
import { arg } from "@unified-latex/unified-latex-builder";
import * as Ast from "@unified-latex/unified-latex-types";
import { ArgumentParser } from "@unified-latex/unified-latex-types";
Expand Down
3 changes: 3 additions & 0 deletions packages/unified-latex-util-arguments/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-catcode/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-comments/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-environments/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-glue/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-html-like/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-ligatures/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-macros/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-packages/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-parse/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-pgfkeys/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-replace/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-scan/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-split/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-to-string/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-trim/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
3 changes: 3 additions & 0 deletions packages/unified-latex-util-visit/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
2 changes: 1 addition & 1 deletion packages/unified-latex/tests/parse.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { trimRenderInfo } from "@unified-latex/unified-latex-util-render-info";
import { VFile } from "unified-lint-rule/lib";
import util from "util";
import { processLatexToAstViaUnified } from "..";
import "../../test-common";
import { processLatexToAstViaUnified } from "../libs/unified-latex";

/* eslint-env jest */

Expand Down
3 changes: 3 additions & 0 deletions packages/unified-latex/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../../tsconfig.test.json"
}
1 change: 0 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"declarationMap": true,
"moduleResolution": "node",
"resolveJsonModule": true,
"types": ["vitest/globals"],
"paths": {
"@unified-latex/*": ["./packages/*"]
}
Expand Down
14 changes: 14 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.build.json",
"include": [
"**/*.ts"
],
"exclude": ["**/*.d.ts", "node_modules", "scripts", "*.config.ts"],
"compilerOptions": {
"rootDir": "./packages",
"paths": {
"@unified-latex/*": ["./packages/dist/*"]
},
"types": ["vitest/globals"]
}
}
Loading