Creating Auto Word Breaking Add-on for Google Documents

Hey everyone! I’m trying to figure out how to create automatic word breaking functionality in Google Docs, similar to what you get in Microsoft Word or LaTeX with Babel. I need this to work for both German and English text.

I’m pretty new to Google Apps Script and don’t really know where to start with coding an extension for this. Has anyone here built something like this before? Could someone point me in the right direction with some sample code that I could use as a starting point?

Any help would be really appreciated. Thanks!

You’ll need to use Google Apps Script’s Document service, specifically the DocumentApp class. Start with DocumentApp.getActiveDocument() to grab the active doc, then loop through text using getBody().getText() or editAsText() methods. The tricky part is hyphenation rules - Google Docs doesn’t have the language-specific word breaking that desktop apps do. German’s especially tough since compound words work differently than English. I’ve had decent luck using regex to find word boundaries and syllable patterns for basic cases. Here’s what I’d do: create a custom menu that triggers your script, scan paragraphs for long words hitting line boundaries, then insert soft hyphens (Unicode U+00AD) where they should break. Start with common prefixes and suffixes before diving into complex syllable detection.

I did something like this last year for our multilingual docs. The biggest pain is that Google Apps Script can’t access hyphenation dictionaries like Word can. I ended up using an external hyphenation library with URL fetch requests, but it slowed things down badly on longer docs. Check out the Hyphenopoly JavaScript library - it’s got solid German support. The tricky bit is getting the Document API to drop soft hyphens in the right spots without breaking your formatting. I’d start with basic text replacement functions before tackling the language detection stuff.

totally agree, the API can be super tricky! check out the document body for sure. i did something similar with soft hyphens for long words before, it worked okay. the apps script docs are a bit basic though, might be hard for what you need.