# Tag Info

7

Yes: TeX can open files for writing and therefore overwrite files. Depending on the TeX distribution, there might be some security restrictions (no files in parent directories, ...). There is a shell escape feature (also called "write18"), which can be used for malicious code. Again, there are some security restrictions. For example, TeX Live only enables ...

9

Another variant with tcolorbox with call outs: \documentclass{article} \usepackage[many]{tcolorbox} \usetikzlibrary{shapes.callouts} \tikzset{note/.style={rectangle callout,fill=#1}} \newtcolorbox[auto counter]{mybox}[1][]{ colback=white, left=0.5ex, top=1ex, right=0.5ex, bottom=0ex, arc=0pt, outer arc=0pt, leftrule=1pt, ...

7


4

My own attempt at a solution is below, with improvements kindly provided by @egreg and @DavidCarlisle. \documentclass{standalone} \makeatletter \newcommand\addstarred[1]{% \expandafter\let\csname\string#1@nostar\endcsname#1% ...

0

In case of scrbook use option openany and insert \cleardoublepages manually. It's not exactly the answer to the question, still, I decided to use this method.

3

You have indicated that you use the scrbook document class. If you want to redefine \chapter (and \chapter*) to execute \clearpage instead of \cleardoublepage, I suggest you load the etoolbox package and use its \patchcmd macro to modify the chapter macro: \usepackage{etoolbox} \patchcmd{\chapter}{\cleardoublepage}{\clearpage}{}{}

4

You put nothing into the horizontal/vertical list when \toto is empty. Thus the \spacefactor manipulating is redundant (see the accepted answer). The following code is sufficient for this task: \def\hideme{\ifdim\lastskip>0pt \ignorespaces\fi} \def\todo#1{#1} % or: \def\todo#1{\hideme}

3

You can't. The value is converted to a PDF string and not typeset by TeX. Therefore the stomach of TeX is not available during the conversion. That means, assignments, definitions, non-expandable macros will not work and can even break. Scanning for the optional argument is implemented via \futurelet in LaTeX, an assignment. Therefore \futurelet would be ...

5

A classical implementation allowing also exponents: \newcount\tmpnum \def\env#1{\sigma \tmpnum=#1\relax \envA{}} \def\envA{\ifnum\tmpnum>0 \advance\tmpnum by-1 \expandafter\envB \else \expandafter\envC \fi} \def\envB#1{\envA{#1'}} \def\envC#1{#1} $\env{1}\env{2}\env{4}^2$

4

With xparse and expl3 you can have a better interface for defining the matrices. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\definematrix}{O{default}m} { \flyx_define_matrix:nn { #1 } { #2 } } \NewDocumentCommand{\usematrix}{O{default}m} { \flyx_use_matrix:nn { #1 } { #2 } } ...

4

It is still not clear what flexibility you need in setting the values, but here is one possibility that may or may not suffice. \documentclass{article} %\usepackage{polyglossia} \usepackage{forloop} \newcommand{\valuesA}[2]{ \ifcase#1% \ifcase#2% value a% \or% value b% \or% value c% ...

5

Of the examples you give, only this one makes any difference: \textbf {text} %or zzz Putting a space before a comment introduces a space, the above will typeset as text zzz Compare with \textbf {text}%or zzz which typesets as textzzz

8

At many places those spaces do not harm: After command names (consisting of letters) spaces are ignored as "end of command name"). Example: space in \textbf {text}. TeX refuses to take a space as undelimited argument unless it is surrounded by braces. Example: second space in \frac {1} {2} LaTeX uses the \@ifnextchar for the optional star and optional ...

0

As variant as a description list. The leftmargin is an optional argument (4em by default): \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{xparse} \usepackage{enumitem} \newlist{acroglossary}{description}{1} \setlist[acroglossary]{leftmargin = 4em, labelwidth =0pt, labelsep=!}% \DeclareDocumentCommand \acro { m m o } {% ...

5

You could also use lists (this is the way I would do it). Load enumitem and \begin{description}[font=\normalfont,leftmargin=5em,labelwidth=5em,labelsep=0pt] \item[TCP] Transmission Control Protocol \\ This is an explanation that can be pretty long and should be indented the same even if it extends into a new line. ...

15

The classical way is using \@bsphack and \@esphack. They are used by \label or \index, both supposed to be invisible/empty regarding spacing. These commands remember, if there is a space before the command. If yes, the second space afterwards is suppressed by \ignorespaces. The commands are defined in the LaTeX kernel: \def\@bsphack{% \relax \ifhmode ...

10

It doesn't really generate space it's just that you have added two spaces, you would see same from a {} b with one space before and one after. But you can end your command with \ignorespaces to ignore the following space. \newcommand{\todo}[1]{\ignorespaces}

9

A classical implementation allowing also exponents: \documentclass{article} \makeatletter \newcommand{\env}[1]{% \sigma \expandafter\startm@keprimes\expandafter{\romannumeral#1000@}% } \def\startm@keprimes#1{\m@keprimes{}#1} \def\m@keprimes#1#2{% \if#2@% \expandafter\@firstoftwo \else \expandafter\@secondoftwo \fi {#1}% ...

6

A simple solution supporting a max of four primes \documentclass{article} \newcommand{\env}[1]{$\sigma\ifcase#1% \or'\or''\or'''\or''''\else^{#1}\fi$} \begin{document} Example: \env{1} \env{2} $\sigma''$ \env{4} \env{5} \end{document} I know it's ugly to type all the cases but in this way you can preserve the right spacing between ...

0

I'm also interested in having something like this, so I've written a short Python script, available from Github here. It's a bit crude, but for sensibly organized macro files (e.g. every \newcommand should appear at the beginning of a line) it seems to achieve what we want. Two notes: My script doesn't actually run TeX to see which macros are used (though ...

0

Use the clipboard package to copy and paste content (either in the same document, or across multiple documents). \documentclass{article} \usepackage{clipboard} \begin{document} \Copy{MyKey}{piece of text} \Paste{MyKey} \end{document} Output:

16

\documentclass{article} \usepackage{xcolor} \usepackage[T1]{fontenc} \begin{document} \def\hashtag{% \textcolor{cyan}{\#}% \begingroup \color{red}% \xhashtag} \def\xhashtag{\futurelet\tmp\xxhashtag} \def\xyhashtag#1{\xhashtag} \def\xxhashtag{% \ifcat a\noexpand\tmp \tmp\expandafter\xyhashtag \else \endgroup \fi} \newenvironment{post}[2]{% #1 ...

8

Customizable at will (but of course rather slow): \documentclass{article} \usepackage{xcolor,environ,xparse,l3regex} \ExplSyntaxOn \NewDocumentEnvironment{post}{mm} { \char_set_catcode_other:N \# % change the catcode not to confuse \innerpost \char_set_catcode_other:N \_ #1~said~on~#2\tl_to_str:n {:}\quote \innerpost % absorb the contents } { ...

7

There are two problems here. The catcode changing (which was solved in previous answers) and your wish that the argument of hash ends by "space OR hash". Your example: What? #confused#lost#savingspace I guess that this second problem isn't solved in previous answers. It could be solved in general, see this thread. But we needn't so complicated code in ...

1

This version resembles the version of egreg, but it regards the (total) section number, such, that there is no pagebreak just before the first section occurs (unless manually forced) \documentclass[12pt]{article} \usepackage{etoolbox}% \usepackage{blindtext}% \usepackage{assoccnt}% \let\LaTeXStandardSection\section \newcounter{totalsection}% ...

3


2

This short code sets “#” active inside the environment, and defines # to be (in this case) equal to \# (chek the handy functions \char_set_active:Npn or \char_set_eq:NN). \documentclass{scrartcl} \usepackage{xparse} \ExplSyntaxOn \NewDocumentEnvironment { post } { } { \quote \char_set_active_eq:NN \# \# } { \endquote } \ExplSyntaxOff \begin{document} ...

4

The simple answer here is that you need to escape # and use \#: some chars are not 'safe' on their own but the escaped versions always are. A classic example is %, which would start a comment normally but doesn't when you use \%. As David says, TeX always allows the use of single-character commands as part of the backtick syntax in contexts such as ...

4

you can use \# The backtick notation takes a single character or a single character control token, for this reason.

18

There are at least a couple of ways you could do this: catcode changes or the \lowercase 'trick'. As you've started off with catcodes, I'll stick with that. What you need to remember is you are tokenizing material when you do \newenviroment. As such, you need to change catcodes before the definition: \documentclass{article} \newcommand\maketag[1]{\##1} ...

3

In every case below, remove the extraneous braces: \def\WPpagequestion{\WPhomepagebase 201545} to prevent those braces from being included in the URL. Plain TeX A Plain TeX way for solving this would be: \def\href#1#2{% \begingroup\def\x{\endgroup\goto{#1}[url(}% \expandafter\x#2)]% } or the more drastic: \def\href#1#2{% ...

22

Well, I'm not the perfect one to explain certain things in English. But basically what \makeatletter does (when executed) is change the catcode of @ so it can be part of a macro name. However, when defining something (or when grabbing an argument of a macro), the tokens are stored (that's what happens with \verb inside arguments, it doesn't work). So in ...

4


6

Just absorb the mandatory argument and “remember” it: \makeatletter \newcommand{\foo}[1]{% \@ifnextchar[{\foo@aux{#1}}{\foo@aux{#1}[default]}% } \def\foo@aux#1[#2]{% mandatory is #1', optional is `#2'% } \makeatother of course this is not very robust and \DeclareRobustCommand should be used. A syntax like \foo{a}[b]{c} where the optional argument ...

5

Let's see what happens. With the first \names{Paul,Peter,Hans}{group1} command, you redefine \List to contain group1. With the second \names{Erik,Robert}{group2}, \List is not empty any more, so you define it to be \OldList,group2 where \OldList expands to group1. Now the problem appears: with the third command you're doing \let\OldList\List, so \OldList ...

2

Here is an expl3 version of your code. The \List macro removes all duplicates from the list of groups, such that you can do \names{...}{groupX} twice without having groupX twice in the output. \documentclass{article} \pagestyle{empty} \usepackage{xparse} \ExplSyntaxOn \seq_new:N \l_gilean_groups_seq \NewDocumentCommand \names { m m } { \gilean_names:nn ...

3

I suggest the well-defined/tested macros from etoolbox. With \listgadd{\List}{} it's possible to define a list. A comma separated value list can be added with \forcsvlist{\listgadd{\List}}{#1}, for example. With a macro \shownames[2] one can loop through the list, the current list entry is contained in the last parameter of the macro via ...

1


4


4

This solution creates a file \jobname.use which tracks, which commands have been used. You add a command to the list by doing \ifused\<command>{<hook>}. In the example I used \patchcmd from etoolbox to remove \bfseries from \l@chapter. Doing \ifused twice for the same command will produce errors. \documentclass{book} \usepackage{xparse,etoolbox} ...

4

The existence of a (LaTeX) counter can be tested with \@ifundefined{c@<argument>}: \newcommand\andrea@test@count[1]{% \@ifundefined{c@#1} {% the counter doesn't exist \newcounter{#1}\setcounter{#1}{1}% } {% the counter exists \stepcounter{#1}% }% } Full example \documentclass{article} % \makeatletter ...

2

This is an extension to @egreg's answer using another answer by @egreg. With this code you can enter a whole sentence in \censor and all words initially added to a list using \addcensor are replaced by grawlixes. The argument to \addcensor can be either a single word or a comma separated list. \documentclass{article} \usepackage{xparse,pgf} \ExplSyntaxOn ...

3


5


2

Another solution, using my package calculator: command \LENGTHDIVIDE divides two lengths and returns a number. For example, \LENGTHDIVIDE{\newdashw}{\dashw}{\theRatio} \documentclass{article} \usepackage{calculator} % Load calculator \usepackage{fontspec} \setmainfont{TeX Gyre Schola} \def\hairspace{\kern .08333em} \newlength\dashw ...

2

In memoir you can use the article option in order to have chapters that look like sections in an article class, but without loosing a sectioning level. For add \S before the number can be solved with a redefinition of \chapternamenum. An example with only the relevant code: \documentclass[article]{memoir} ...

4

This sets up the section format and titling using memoir macros. Thanks to Paul Gessler for pointing out that memoir (and not just me) uses the standard method for defining the numbering. Note that it is important to use semantic markup i.e. to use \maketitle etc. rather than setting stuff manually or defining your own alternative commands. So you want ...

7

I would set up one wrapper .tex file for each variant. This should contain only those things from the preamble which you need to change. Everything else goes in the main .tex file so that you do not need to worry about keeping things in sync when you make modifications to the content. Then \input the main file. For example: %% diss-1.tex ...

Top 50 recent answers are included