The getState and setState preserve folder locations. You could use a list of expressions you want to have in advance, then load the page and move them into a folder, and give yourself a button that saves the getState(). You can keep that as a JSON somewhere in your file system or an object in your script, then pass it back to setState and those variables will still be in the folder you put them in. If you want to go against the documentation advice for treating the getState() as opaque, then you could do this...
calcInstance.setExpression({
type: 'folder',
id: 'testFolder',
title: 'Try this out',
secret: true
});
calcInstance.setExpression({
id: 'test',
latex: `t_{est} = 42`,
secret: true
});
const testString = JSON.stringify(calcInstance.getState());
let putFolder = testString.replace('"id":"test"', '"id":"test","folderId":"testFolder"');
calcInstance.setState(JSON.parse(putFolder));