Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
b8844ea
structs: fix for crash on error in reflectx.Structs
rcoreilly Jun 15, 2026
087b478
structs: text/tex uses new star-tex support for latex instead of just…
rcoreilly Jun 23, 2026
f59ac6e
structs: tex working for all tests, using article mode -- standalone …
rcoreilly Jun 23, 2026
6e0632a
structs: latexmath fully working with shaped -- requires standalone.
rcoreilly Jun 23, 2026
3c1caac
structs: add texcache package, which supports savinng / loading math …
rcoreilly Jun 23, 2026
b7a9e0e
structs: delete unused from texcache
rcoreilly Jun 23, 2026
c6bb04e
structs: dvi font rendering is a mess.. the bearings are not correct …
rcoreilly Jun 24, 2026
f1b75f0
structs: massive fixes in tex charsets and path rendering -- all majo…
rcoreilly Jun 24, 2026
d08bcc9
structs: operators test all good with fixes
rcoreilly Jun 24, 2026
147867f
structs: rest of misc symbols test
rcoreilly Jun 24, 2026
0ca9adf
fix \dot, \ddot, and add SetShapeMath to be tex-free in content
rcoreilly Jun 25, 2026
cf06d16
structs: sqrt fix and start on html fix
rcoreilly Jun 25, 2026
c1654dd
structs: include all necessary texmf files -- should allow testing to…
rcoreilly Jun 25, 2026
0c7f8ca
structs: install of texmf files working; CI error is just changed output
rcoreilly Jun 25, 2026
b36458a
structs: trim space for shape math, and remove debugging.
rcoreilly Jun 25, 2026
283c178
structs: web version now working: some bizzarre inability to embed a …
rcoreilly Jun 25, 2026
0673291
structs: minor cleanup, ready to go finally!
rcoreilly Jun 25, 2026
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
1 change: 1 addition & 0 deletions base/reflectx/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ func SetFieldsFromMap(obj any, vals map[string]any) error {
fld, err := FieldByPath(objv, k)
if err != nil {
errs = append(errs, err)
continue
}
err = SetRobust(PointerValue(fld).Interface(), v)
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions content/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ type Content struct {
// The previous and next page, if applicable. They must be stored on this struct
// to avoid stale local closure variables.
prevPage, nextPage *bcontent.Page

// if non-nil, a message is sent when content page is rendered
renderChan chan struct{}
}

func init() {
Expand Down Expand Up @@ -478,6 +481,13 @@ func (ct *Content) loadPage(w *core.Frame) error {
return nil
}

func (ct *Content) RenderWidget() {
ct.Splits.RenderWidget()
if ct.renderChan != nil {
ct.renderChan <- struct{}{}
}
}

// makeTableOfContents makes the table of contents and adds it to [Content.leftFrame]
// based on the headings in the given frame.
func (ct *Content) makeTableOfContents(w *core.Frame, pg *bcontent.Page) {
Expand Down Expand Up @@ -676,3 +686,21 @@ func (ct *Content) PageRefs(page *bcontent.Page) *core.Frame {
fr.SetScene(ct.Scene)
return fr
}

// LoadEachPage is a helper function to iterate through loading each page,
// which is used for updating the math cache.
func (ct *Content) LoadEachPage(after func()) error {
ct.renderChan = make(chan struct{})
go func() {
for _, pg := range ct.pages {
fmt.Println("\n#### page:", pg.URL)
ct.OpenEvent(pg.URL, nil)
<-ct.renderChan
fmt.Println("rendered:", pg.URL)
}
if after != nil {
after()
}
}()
return nil
}
22 changes: 21 additions & 1 deletion content/examples/basic/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@
package main

import (
"bytes"
"embed"

"cogentcore.org/core/base/errors"
"cogentcore.org/core/content"
"cogentcore.org/core/core"
"cogentcore.org/core/events"
"cogentcore.org/core/htmlcore"
_ "cogentcore.org/core/text/tex"
"cogentcore.org/core/icons"
"cogentcore.org/core/keymap"
"cogentcore.org/core/text/tex/texcache"
"cogentcore.org/core/tree"
_ "cogentcore.org/core/yaegicore"
)

//go:generate go run ./genmath.go

//go:embed content
var econtent embed.FS

//go:embed mathcache.json.gz
var mathcache []byte

func main() {
texcache.ReadGzip(bytes.NewBuffer(mathcache))
texcache.SetShapeMath() // only use cached!
// rasterx.UseGlyphCache = false
content.Settings.SiteTitle = "Cogent Content Example"
content.OfflineURL = "https://example.com"
Expand All @@ -29,6 +41,14 @@ func main() {
core.NewToolbar(bar).Maker(func(p *tree.Plan) {
ct.MakeToolbar(p)
ct.MakeToolbarPDF(p)
tree.Add(p, func(w *core.Button) {
w.SetText("SaveMath").SetIcon(icons.Search).SetKey(keymap.Find).
SetTooltip("Save cached math rendering")
w.OnClick(func(e events.Event) {
e.SetHandled()
errors.Log(texcache.SaveAs("mathcache.json"))
})
})
})
})
b.RunMainWindow()
Expand Down
42 changes: 42 additions & 0 deletions content/examples/basic/genmath.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2024, Cogent Core. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build ignore

package main

import (
"embed"
"fmt"

"cogentcore.org/core/base/errors"
"cogentcore.org/core/content"
"cogentcore.org/core/core"
"cogentcore.org/core/events"
_ "cogentcore.org/core/text/tex"
"cogentcore.org/core/text/tex/texcache"
)

//go:embed content
var econtent embed.FS

//go:embed mathcache.json.gz
var mathcache embed.FS

func main() {
texcache.OpenFS(mathcache, "mathcache.json.gz") // note: doesn't work on web / js
content.Settings.SiteTitle = "Generate Cache Math"
content.OfflineURL = "https://example.com"
b := core.NewBody("Generate Cache Math")
ct := content.NewContent(b).SetContent(econtent)
b.OnShow(func(e events.Event) {
ct.LoadEachPage(func() {
texcache.DeleteUnused()
errors.Log(texcache.SaveAs("mathcache.json.gz"))
fmt.Println("ALL DONE!")
core.TheApp.QuitReq()
})
})
b.RunMainWindow()
}
Binary file added content/examples/basic/mathcache.json.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion content/typegen.go

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

7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/bramvdbogaerde/go-scp v1.6.0
github.com/chewxy/math32 v1.11.2
github.com/cogentcore/reisen v0.0.0-20240814194831-4d884b6e7666
github.com/cogentcore/star-tex v0.7.2-0.20260625151004-a16970c7d698
github.com/cogentcore/yaegi v0.0.0-20260116172027-700fbf8949f3
github.com/coreos/go-oidc/v3 v3.17.0
github.com/ericchiang/css v1.4.0
Expand Down Expand Up @@ -45,11 +46,11 @@ require (
golang.org/x/text v0.37.0
golang.org/x/tools v0.44.0
gopkg.in/yaml.v3 v3.0.1
star-tex.org/x/tex v0.7.1
)

require (
codeberg.org/go-pdf/fpdf v0.11.0 // indirect
codeberg.org/go-pdf/fpdf v0.11.1 // indirect
git.sr.ht/~sbinet/overlayfs v0.1.1 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dlclark/regexp2 v1.11.5 // indirect
Expand Down Expand Up @@ -77,6 +78,6 @@ require (
golang.org/x/mod v0.35.0 // indirect
golang.org/x/sync v0.20.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
modernc.org/knuth v0.5.4 // indirect
modernc.org/knuth v0.5.5 // indirect
modernc.org/token v1.1.0 // indirect
)
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
codeberg.org/go-pdf/fpdf v0.11.0 h1:n3I8WISQ1cr0S2rvx9DOlE/GypbcimMWqLpel3slHmY=
codeberg.org/go-pdf/fpdf v0.11.0/go.mod h1:Y0DGRAdZ0OmnZPvjbMp/1bYxmIPxm0ws4tfoPOc4LjU=
codeberg.org/go-pdf/fpdf v0.11.1 h1:U8+coOTDVLxHIXZgGvkfQEi/q0hYHYvEHFuGNX2GzGs=
codeberg.org/go-pdf/fpdf v0.11.1/go.mod h1:Y0DGRAdZ0OmnZPvjbMp/1bYxmIPxm0ws4tfoPOc4LjU=
git.sr.ht/~sbinet/cmpimg v0.1.0 h1:E0zPRk2muWuCqSKSVZIWsgtU9pjsw3eKHi8VmQeScxo=
git.sr.ht/~sbinet/cmpimg v0.1.0/go.mod h1:FU12psLbF4TfNXkKH2ZZQ29crIqoiqTZmeQ7dkp/pxE=
git.sr.ht/~sbinet/overlayfs v0.1.1 h1:HvCHXT1cs8RMSjNLQXxPPosB2hgR3tRC8RniH0f3ESg=
git.sr.ht/~sbinet/overlayfs v0.1.1/go.mod h1:TmrIWKlxyPJJ7vchTqk85DUcW6IDsIa7ONLvSGIw438=
github.com/Bios-Marcel/wastebasket/v2 v2.0.3 h1:TkoDPcSqluhLGE+EssHu7UGmLgUEkWg7kNyHyyJ3Q9g=
github.com/Bios-Marcel/wastebasket/v2 v2.0.3/go.mod h1:769oPCv6eH7ugl90DYIsWwjZh4hgNmMS3Zuhe1bH6KU=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
Expand Down Expand Up @@ -29,6 +31,8 @@ github.com/chewxy/math32 v1.11.2 h1:IufN08Zwr1NKuWfY+4Tz55BcwKmyKKNdOP7KtumehnM=
github.com/chewxy/math32 v1.11.2/go.mod h1:dOB2rcuFrCn6UHrze36WSLVPKtzPMRAQvBvUwkSsLqs=
github.com/cogentcore/reisen v0.0.0-20240814194831-4d884b6e7666 h1:gmXMw/Xcva/2V5qRO920q4am1odNE0xFEGBzG7y7cus=
github.com/cogentcore/reisen v0.0.0-20240814194831-4d884b6e7666/go.mod h1:HoDh/nWYrLffGjfVxUmbJHb0yZvcV3TwrN73WurddNs=
github.com/cogentcore/star-tex v0.7.2-0.20260625151004-a16970c7d698 h1:GsehCn/Dw8hhYAonDQO48EJz63sAAF4wxEhHmHt/xKA=
github.com/cogentcore/star-tex v0.7.2-0.20260625151004-a16970c7d698/go.mod h1:pdlQowLCSMiGfeOM6M7yz09OmR2fzlmFYcvR/u6QaRQ=
github.com/cogentcore/yaegi v0.0.0-20260116172027-700fbf8949f3 h1:y3Djpt/g3QTjFdj8cpvy/r8FsZsEa7PqHGjgsKXbta0=
github.com/cogentcore/yaegi v0.0.0-20260116172027-700fbf8949f3/go.mod h1:XkOm++pRmWlk85p+hw71ZItfTeRdzqG23+2xjP9eb+M=
github.com/coreos/go-oidc/v3 v3.17.0 h1:hWBGaQfbi0iVviX4ibC7bk8OKT5qNr4klBaCHVNvehc=
Expand Down Expand Up @@ -209,11 +213,9 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EV
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
modernc.org/knuth v0.5.4 h1:F8mDs7ME3oN9eyx01n6/xVmJ4F5U/qEhSYPnPXaZrps=
modernc.org/knuth v0.5.4/go.mod h1:e5SBb35HQBj2aFwbBO3ClPcViLY3Wi0LzaOd7c/3qMk=
modernc.org/knuth v0.5.5 h1:6lap2U/ISm8aC/4NU58ALFCRllNPaK0EZcIGY/oDgUg=
modernc.org/knuth v0.5.5/go.mod h1:e5SBb35HQBj2aFwbBO3ClPcViLY3Wi0LzaOd7c/3qMk=
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=
rsc.io/pdf v0.1.1 h1:k1MczvYDUvJBe93bYd7wrZLLUEcLZAuF824/I4e5Xr4=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
star-tex.org/x/tex v0.7.1 h1:4qGAByRyY0WQsOjtcHlxz+FgrYxz8fzxIds2Gjepp5U=
star-tex.org/x/tex v0.7.1/go.mod h1:Y3y0U7sZTltTh/CDZIx0oAtMjG7eMaTuTtvDZGdyhJo=
2 changes: 1 addition & 1 deletion paint/pdf/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (r *PDF) textRun(style *styles.Paint, m math32.Matrix2, run *shapedgt.Run,
psty := *style
psty.Stroke.Color = run.StrokeColor
psty.Fill.Color = fill
r.Path(*run.Math.Path, &psty, math32.Identity2())
r.Path(run.Math.Path, &psty, math32.Identity2())
r.w.PopStack()
return
}
Expand Down
4 changes: 2 additions & 2 deletions paint/renderers/htmlcanvas/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"cogentcore.org/core/paint/render"
)

func (rs *Renderer) writePath(pt *ppath.Path) {
func (rs *Renderer) writePath(pt ppath.Path) {
rs.ctx.Call("beginPath")
for scanner := pt.Scanner(); scanner.Scan(); {
end := scanner.End()
Expand Down Expand Up @@ -48,7 +48,7 @@ func (rs *Renderer) RenderPath(pt *render.Path) {
rs.setTransform(&pt.Context)

if style.HasFill() || style.HasStroke() {
rs.writePath(&pt.Path)
rs.writePath(pt.Path)
}

rs.curRect = pt.Path.FastBounds().ToRect() // TODO: more performance optimized approach (such as only computing for gradients)?
Expand Down
2 changes: 1 addition & 1 deletion paint/renderers/rasterx/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (rs *Renderer) TextRun(ctx *render.Context, run *shapedgt.Run, ln *shaped.L
lineW := max(fsz/16, 1) // 1 at 16, bigger if biggerr
if run.Math.Path != nil {
rs.Path.Clear()
PathToRasterx(&rs.Path, *run.Math.Path, ctx.Cumulative, off)
PathToRasterx(&rs.Path, run.Math.Path, ctx.Cumulative, off)
rf := &rs.Raster.Filler
rf.SetWinding(true)
rf.SetColor(fill)
Expand Down
1 change: 0 additions & 1 deletion text/paginate/paginate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"cogentcore.org/core/math32"
"cogentcore.org/core/paint"
"cogentcore.org/core/styles/units"
_ "cogentcore.org/core/text/tex"
)

// Paginate organizes the given input widget content into frames
Expand Down
4 changes: 4 additions & 0 deletions text/parse/languages/golang/parsedir.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"log"
"os"
"path/filepath"
"slices"
"strings"
"sync"
"unicode"
Expand Down Expand Up @@ -165,6 +166,9 @@ func (gl *GoLang) ParseDirImpl(fs *parse.FileState, path string, opts parse.Lang
// fmt.Printf("No go files, bailing\n")
return nil
}
files = slices.DeleteFunc(files, func(s string) bool {
return strings.Contains(s, "_test.go") || strings.HasPrefix(s, "_")
})
for i, pt := range files {
files[i] = filepath.Join(pkgPathAbs, pt)
}
Expand Down
2 changes: 1 addition & 1 deletion text/shaped/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Run interface {

// Math holds the output of a TeX math expression.
type Math struct {
Path *ppath.Path
Path ppath.Path
BBox math32.Box2
}

Expand Down
2 changes: 2 additions & 0 deletions text/shaped/shaped_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ func TestEmoji(t *testing.T) {
}

func TestMathInline(t *testing.T) {
t.Skip("this requires full latex install on CI, not worth it -- just test locally")
tests := []struct {
name string
math string
Expand All @@ -350,6 +351,7 @@ func TestMathInline(t *testing.T) {
}

func TestMathDisplay(t *testing.T) {
t.Skip("this requires full latex install on CI, not worth it -- just test locally")
tests := []struct {
name string
math string
Expand Down
7 changes: 5 additions & 2 deletions text/shaped/shaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ var (
// given math expression, in TeX syntax.
// Import _ cogentcore.org/core/text/tex to set this function
// (incurs a significant additional memory footprint due to fonts
// and other packages).
ShapeMath func(expr string, fontHeight float32) (*ppath.Path, error)
// and other packages), or call texcache.SetShapeMath() from
// cogentcore.org/core/text/texcache for fully cached version that
// saves on all the memory, but requires all equations to be generated
// in advance and saved.
ShapeMath func(expr string, fontHeight float32) (ppath.Path, error)
)

// Shaper is a text shaping system that can shape the layout of [rich.Text],
Expand Down
Loading
Loading