I’m working on a Google Docs script to set up a specific paragraph style for my academic paper. I’m new to this and could use some guidance. Here’s what I’m trying to achieve:
Indent: 4 cm
Font: Arial, size 10
Single line spacing
1.5 spacing before and after citations
Justified alignment
I found a script online that adds custom styles, but I’m not sure how to modify it for my needs. Here’s a simplified version of what I’m working with:
function customStyle() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var style = {};
style[DocumentApp.Attribute.INDENT_FIRST_LINE] = 40;
style[DocumentApp.Attribute.FONT_FAMILY] = DocumentApp.FontFamily.ARIAL;
style[DocumentApp.Attribute.FONT_SIZE] = 10;
style[DocumentApp.Attribute.LINE_SPACING] = 1;
style[DocumentApp.Attribute.SPACING_AFTER] = 15;
style[DocumentApp.Attribute.SPACING_BEFORE] = 15;
style[DocumentApp.Attribute.HORIZONTAL_ALIGNMENT] = DocumentApp.HorizontalAlignment.JUSTIFY;
body.setAttributes(style);
}
Can someone help me adjust this for my specific requirements? I’m really stuck and would appreciate any tips!
hey mate, i can help ya out! ur script looks good, just need a few tweaks. change INDENT_FIRST_LINE to 40 (4cm), and add INDENT_START: 40 for left indent. for citations, you’ll need a separate function to detect and adjust spacing. lemme know if u need more help!
I’ve worked with Google Docs scripts for academic formatting before, and I can offer some advice. Your script is on the right track, but there are a few adjustments needed.
For the indent, use INDENT_START instead of INDENT_FIRST_LINE to achieve a 4 cm left indent and set both to 113.39 (4 cm in points). For line spacing, consider using LINE_SPACING_EXACT and set it to 10 for single spacing.
The citation spacing is trickier and would require a separate function to detect citations and adjust spacing accordingly. Using named styles might also provide more flexibility.
I’ve been in your shoes, struggling with Google Docs scripts for academic papers. Here’s what I’ve learned:
The script you’ve got is a solid starting point. For the 4 cm indent, you’ll want to use INDENT_START and set it to 113.39 (that’s 4 cm in points). For the font and size, you’re spot on.
The tricky part is the spacing for citations. You’d need to create a separate function to detect citations and adjust the spacing accordingly. I’ve found using regular expressions can help identify citation patterns.
One tip: consider using named styles instead of directly applying attributes. It makes it easier to update formatting across the entire document later.
Remember to test your script on a copy of your document first. It can save you a lot of headaches!