0

I am not sure if what I'm envisioning is possible, but I am not referring to the listings package (which is what all of my searches are yielding).

I reuse a lot of my LaTeX code. I recently figured out how to replicate large parts of my preamble (which has over a dozen packages and user-defined commands) by making a single "custom" package which I call in my documents. However, there are parts of my preamble that I also reuse but have change small parts of in each document.

For instance, I have the style of my title page defined, but the title itself, the date, etc. needs to change. Is it possible to do something where I put my code into another document and call it in each document with some parameters? For instance, if I put everything in a class called mytitle and then call that specific package in my document:

\usepackage[title,subtitle,author,date]{mytitle}

where those options are defined in the package itself?

I thought that classes would be the right option, but it's looking like that isn't the right solution.

5
  • Yes, possible. You could use key=value for the title page parameters. Either as document class options or in the preamble. Or use the classical way with normal commands to store your data. – Johannes_B Jul 29 '20 at 2:52
  • Yes, this is possible, with both classes and package (which in that respect are indistinguishable.) For the kind of thing you are thinking of doing, key value options make the most sense: \usepackage[title={my title}, author={Author), ... ]{mypackage}. There are numerous key value packages around. See A big list of every keyval package. The kvoptions and pgfopts (which uses pgfkeys) are two choices specifically for processing package/class options. – Alan Munn Jul 29 '20 at 2:52
  • tex.stackexchange.com/a/210280 – Johannes_B Jul 29 '20 at 2:53
  • Wow, I may be out of my league here. Would it be considered bad form to use a package? I'm more comfortable with that now that I've done it before... @AlanMunn, is there a reason I would have to put "title={my title}" etc. or would I just be able to put my desired title as the option value? – Publius Jul 29 '20 at 2:59
  • 1
    @Publius The key-value packages have already done the hard work of linking the option key with the option value. Alternative is you do all that coding. Look at how hyperref does it versus how babel does it. Dummy example: Something like \usepackage[a,b,c,d,e]...: if the item/value is unique ([english,french,german]) = true/false = on/off, the value is enough; but for item/value from a list of values ([cat,123,blue,default]), Tex needs to be told what value links to what option and the key/value method does that concisely ([topic=cat,style=123,headingcolour=blue,mathstyle=default]). – Cicada Jul 29 '20 at 9:55
0

I provided an answer to my ultimate question in this post. But, to answer this part of the question, yes it is possible to import prewritten code, albeit not in the way I was originally planning. (It probably is possible, but I haven't figured it out yet). The answer provided in the link above is a streamlined workaround to the original problem. Wanted to share here in case someone else stumbled upon this post.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.