Merge pull request #1111 from alixander/fix-themed-latex

fix latex uppercasing
This commit is contained in:
Alexander Wang 2023-03-29 20:17:21 -07:00 committed by GitHub
commit 2ad4a8e9cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 369 additions and 193 deletions

View file

@ -14,3 +14,4 @@
- prevent an object's `near` from targeting a text near a constant. [#1100](https://github.com/terrastruct/d2/pull/1100)
- fixes inaccurate bold edge label padding. [#1108](https://github.com/terrastruct/d2/pull/1108)
- Prevents Latex blocks from being uppercased in special themes. [#1111](https://github.com/terrastruct/d2/pull/1111)

View file

@ -1305,8 +1305,10 @@ func (g *Graph) SetDimensions(mtexts []*d2target.MText, ruler *textmeasure.Ruler
}
if g.Theme != nil && g.Theme.SpecialRules.CapsLock && !strings.EqualFold(obj.Attributes.Shape.Value, d2target.ShapeCode) {
if obj.Attributes.Language != "latex" {
obj.Attributes.Label.Value = strings.ToUpper(obj.Attributes.Label.Value)
}
}
labelDims, err := obj.GetLabelSize(mtexts, ruler, fontFamily)
if err != nil {
@ -1455,8 +1457,10 @@ func (g *Graph) Texts() []*d2target.MText {
if obj.Attributes.Label.Value != "" {
text := obj.Text()
if capsLock && !strings.EqualFold(obj.Attributes.Shape.Value, d2target.ShapeCode) {
if obj.Attributes.Language != "latex" {
text.Text = strings.ToUpper(text.Text)
}
}
texts = appendTextDedup(texts, text)
}
if obj.Class != nil {

View file

@ -785,6 +785,46 @@
"labelHeight": 401,
"zIndex": 0,
"level": 1
},
{
"id": "ex",
"type": "text",
"pos": {
"x": 758,
"y": 1031
},
"width": 404,
"height": 52,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "transparent",
"stroke": "N1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "\\\\displaylines{x = a + b \\\\\\\\ y = b + c}\n\\\\sum_{k=1}^{n} h_{k} \\\\int_{0}^{1} \\\\bigl(\\\\partial_{k} f(x_{k-1}+t h_{k} e_{k}) -\\\\partial_{k} f(a)\\\\bigr) \\\\,dt",
"fontSize": 16,
"fontFamily": "mono",
"language": "latex",
"color": "N1",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 404,
"labelHeight": 52,
"zIndex": 0,
"level": 1
}
],
"connections": [
@ -1447,6 +1487,54 @@
"tooltip": "",
"icon": null,
"zIndex": 0
},
{
"id": "(code -> ex)[0]",
"src": "code",
"srcArrow": "none",
"srcLabel": "",
"dst": "ex",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"label": "",
"fontSize": 16,
"fontFamily": "mono",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 959.5,
"y": 903
},
{
"x": 959.5,
"y": 951.4
},
{
"x": 959.5,
"y": 977.1
},
{
"x": 959.5,
"y": 1031.5
}
],
"isCurve": true,
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 0
}
],
"root": {

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 99 KiB

View file

@ -785,6 +785,46 @@
"labelHeight": 401,
"zIndex": 0,
"level": 1
},
{
"id": "ex",
"type": "text",
"pos": {
"x": 1105,
"y": 909
},
"width": 404,
"height": 52,
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"borderRadius": 0,
"fill": "transparent",
"stroke": "N1",
"shadow": false,
"3d": false,
"multiple": false,
"double-border": false,
"tooltip": "",
"link": "",
"icon": null,
"iconPosition": "",
"blend": false,
"fields": null,
"methods": null,
"columns": null,
"label": "\\\\displaylines{x = a + b \\\\\\\\ y = b + c}\n\\\\sum_{k=1}^{n} h_{k} \\\\int_{0}^{1} \\\\bigl(\\\\partial_{k} f(x_{k-1}+t h_{k} e_{k}) -\\\\partial_{k} f(a)\\\\bigr) \\\\,dt",
"fontSize": 16,
"fontFamily": "mono",
"language": "latex",
"color": "N1",
"italic": false,
"bold": false,
"underline": false,
"labelWidth": 404,
"labelHeight": 52,
"zIndex": 0,
"level": 1
}
],
"connections": [
@ -1225,6 +1265,45 @@
"tooltip": "",
"icon": null,
"zIndex": 0
},
{
"id": "(code -> ex)[0]",
"src": "code",
"srcArrow": "none",
"srcLabel": "",
"dst": "ex",
"dstArrow": "triangle",
"dstLabel": "",
"opacity": 1,
"strokeDash": 0,
"strokeWidth": 2,
"stroke": "B1",
"label": "",
"fontSize": 16,
"fontFamily": "mono",
"language": "",
"color": "N2",
"italic": true,
"bold": false,
"underline": false,
"labelWidth": 0,
"labelHeight": 0,
"labelPosition": "",
"labelPercentage": 0,
"route": [
{
"x": 1307.8333333333333,
"y": 824
},
{
"x": 1307.8333333333333,
"y": 909
}
],
"animated": false,
"tooltip": "",
"icon": null,
"zIndex": 0
}
],
"root": {

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 80 KiB

After

Width:  |  Height:  |  Size: 99 KiB

View file

@ -104,7 +104,11 @@ func main() {
}
|
markdown -> code
markdown -> code -> ex
ex: |tex
\\displaylines{x = a + b \\\\ y = b + c}
\\sum_{k=1}^{n} h_{k} \\int_{0}^{1} \\bigl(\\partial_{k} f(x_{k-1}+t h_{k} e_{k}) -\\partial_{k} f(a)\\bigr) \\,dt
|
`,
},
{