51

First of all, \makeatletter is unnecessary in .sty or .cls files, as the default catcode regime includes it; this is presumably to encourage package writers to hide their macros using @-laden names. For this reason, I believe that using this command is harmless in package files. However, using the pair of commands together is harmful, because unlike in a ...


45

For programming packages that implement new functionality for LaTeX2e what you mainly need is the programming layer of LaTeX3. xparse additionally offers you some help for defining user interfaces in 2e style with optional arguments or star forms etc, but you can think of this as the syntactic sugar on top of the functionality your package provides. And in ...


40

TeX is an interpreter and macro processor (the canonical implementation of which written in WEB, a dialect of pascal) it takes in text files consisting of text and macros, and font files (and a few other possible things) and expands the macros and evaluates some expressions defined in the TeX syntax and produces a file description of a sequence of typeset ...


39

A simple rule of thumb is that if you're creating commands that contain data that LaTeX will reread later, you should be using a robust command that is defined using \DeclareRobustCommand. Such data is contained in arguments that typically go into table of contents, list of figures, list of tables etc.; namely, data that are written to an auxiliary file and ...


39

More complicated. \usepackage: can check that the package is newer than a specified version date can have options specified for loading the package can inherit options from the \documentclass line only loads .sty files checks that it is only called after \documentclass and before \begin{document} ensures catcodes are correct for LaTeX package syntax (\...


37

LaTeX does try to encourage a naming scheme Document level commands (\section) lowercase. Package interface commands (\DeclareTextCommandDefault) CamelCase. Package or kernel internal commands (\@text@composite@) lower@case@with@. TeX primitives (\expandafter) lowercase. Mostly this convention is not enforced, and of course one might notice that the ...


36

I don't think syntax highlighting should be done purely in Tex for following reasons: Languages are complicated (context sensitive) and to proper highlight the syntax, you have to implement a full compiler front-end. As an example, here is some simple C++ code: struct foo; // foo is the name of a data type void f(foo param); // function f, taking a foo as ...


36

Technically using plain tex is not an option, plain is the format produced by inputting the file plain.tex into initex and that file is not used in LaTeX at all. It is however true that many of the commands that are defined in plain TeX have commands of the same name defined in LaTeX, and in some of those cases, the definitions are the same. The commands ...


34

In my opinion, it is better to use \newcommand if there are no obvious expansion issues. There are two drawbacks of \DeclareRobustCommand: \DeclareRobustCommand does not check if the macro is predefined. Macros defined by \DeclareRobustCommand are less efficient.


32

My package tcolorbox provides another possible answer for the question. It allows to place the source code before or after the output. With version 2.20, source and output can be set side-by-side. The output can be placed inside a colored box or outside, before the source or after the source. \documentclass{article} \usepackage[skins,listings]{tcolorbox} \...


32

This was a lot more serious in LaTeX2.09 as there LaTeX just executed \makeatletter once before handling all the .sty files (LaTeX2.09 didn't gave the .cls/.sty distinction). So it was a common problem, almost a FAQ, that packages were released that executed \makeatother at the end of the file and they worked in isolation but broke any following "style files"...


32

I would approach the answer to the question a bit differently (though it is essentially equiv to what David said): \par in LaTeX is equivalent to an empty line in the user document! Whatever the LaTeX gives as meaning to the "empty line" in a certain context is what \par would result to. Example given by David: in a tabular empty lines are ignored. But ...


32

NOTE: Real-world application added at end of post! RE-REVISED to re-extend capability (and significantly condense the coding), as detailed here: The following macros are introduced for left-aligned acrostics. Macros for mid-line acrostics are described later in this post. \RAWacrostic{acrostic} - to view acrostic in plain, unaltered mode \SHOWacrostic[# ...


28

Maybe one could say a package is for extending possibilities, a class is for restricting possibilities. If you want to add new features which can help users create specific effects in a lot of different document types, a package is for you. If you want to set sensible defaults and create an optimal environment for efficiently creating documents of a ...


28

Limitations of l3regex On page 12 of the documentation, under "The following features of PCRE or Perl will denitely not be implemented": Recursion: this is a non-regular feature. Back-references: non-regular feature, this requires backtracking, which is prohibitively slow. So it doesn't look like you will be able to track matched/unmatched parentheses ...


26

It's a bad idea to do \countdef\mycount=81 in all flavors of TeX. No discussion allowed. Plain TeX allocates 25 count registers; it can be checked from any tex.log (or plain.log) on your machine. So, if a macro package says \newcount\foo TeX will execute internally \countdef\foo=26, but the actual number should never be used. So, assume you load eplain ...


25

An easy way is to look for the definition of \fmtversion in latex.ltx, e.g. (bash): $ grep edef.fmtversion $(kpsewhich latex.ltx) \edef\fmtversion{2011/06/27} Alternatively (see egreg's comment), you can use: $ texdef -t latex fmtversion \fmtversion: macro:->2011/06/27 Or latex can directly be asked: $ latex '\typeout{\fmtversion}\stop' | grep ...


24

I wrote an article on the LaTeX Community Forum on how to write a LaTeX class file. It's specifically about creating form-style documents, but there is some general class-writing stuff in there, if that's of any use. Edit: there's also Writing a Class File for a Form which is developed from my LC article.


24

As long as you're aware not to do bad things inside your own package (like Ryan Reich's example), you seem to be safe within the bounds of what LaTeX offers. But still dangers lurk around the corner. If I say \usepackage{afterpackage} \AfterPackage{foo}{\input{bar}} \usepackage{foo} and inside foo.sty \makeatother and inside bar.tex \protected@edef\...


24

I agree with kgr generating the actual data should be done by a script. To have a certain readability (in case you need to manually tweak something afterwards, like e.g. highlight something with a special color) you should definitively go with a key-value interface as Qrrbrbirlbel suggested. I'd go with pgfkeys, which is already a part of TikZ. Here's a ...


24

Here's an implementation with amsthm and tcolorbox: \documentclass{article} \usepackage{lipsum} % just for the example \usepackage{amsthm,tcolorbox} \newtheoremstyle{block} {\topsep}% space above {\topsep}% space below {\itshape}% body font {}% indent {\bfseries}% head font {}% punctuation {1em}% space between head and body {(\thmnumber{#2})} \...


23

As there are no tutorials for exactly what you are asking, I will endeavor to provide a short one here to provide an answer to the question, and with the hope that other more experienced users will provide additional information. To understand properly the development of a tikZ/pgf package/library one has to distinguish between the different aspects of the ...


23

TDS structure Assuming your LaTeX package is called foobar. Then according to TDS (A Directory Structure for TeX files) the files would go below the following Directories: TDS:tex/latex/foobar/ (for TeX files: .tex, .sty, images) TDS:doc/latex/foobar/ (for documentation files) TDS:source/latex/foobar/ (for source files .dtx, .ins) Further subdirectories ...


23

Ok, so here's my go: Use LaTeX3. Call texdoc expl3 and texdoc interface3 and read that. This is the first attempt I've seen which tries to take care of interface design for LaTeX on a systematic, wholistic and complete scope. Use LaTeX3. Use LaTeX3. (Note that I don't know by heart what LaTeX3 offers in detail, mainly because I'm not the robustness-loving ...


23

At the moment you use \DeclareOption, your style file is divided into three parts: Pre-options Section (above first \DeclareOption); Options Section (between first \DeclareOption and \ProcessOptions); and Post-options Section (after \ProcessOptions). Whatever is contained within the pre-options section has already been processed. So, the only problem ...


22

All or nearly all packages in the TeX world (e.g., those on CTAN) have a license attached to it. Depending on the license you are allowed to modify the package, but the license may pose restrictions upon you on how you do that. If the license is LPPL (which is the case for many packages in the LaTeX world and beyond) then yes it is allowed to modify the ...


21

I believe it is good practice. There are hundreds of functions in the current LaTeX3 kernel that make a macro programmer's life easier. I wouldn't use such a dramatic indentation as you do and surely I'd use \NewDocumentCommand: \NewDocumentCommand{\tangentcount}{ m } { \int_case:nnn { #1 } { { 1 } { exactly ~ one } { 2 } { exactly ~ two } ...


21

It depends whether the commands you are defining are ever going to be executed at a place where \par doesn't mean \endgraf. For example latex.ltx has \let\tabularnewline\\% \let\par\@empty so if you might want to be evaluated in the scope of those definitions you have to decide whether you want the current definition of \par or of \endgraf.


20

Regarding flat .zip vs. .tds.zip, CTAN now rejects uploads that consist only of a TDS-structure, whether as a .zip or not. They now require creating a "browsing-friendly" relatively flat structure for the main tree. Regarding creation of .tds.zip, I would strongly discourage doing it here. And in general, unless there is a specific reason to do so. ...


20

There are several possibilities. I'll present four different ways. The first two use directly or indirectly the macros \captions<lang> or \extras<lang> which are provided both by babel and polyglossia. babel says the following about those two: \captions<lang> : The macro \captions<lang> defines the macros that hold the texts to ...


Only top voted, non community-wiki answers of a minimum length are eligible