Tag Info

Hot answers tagged

18

This will most likely break everything, \jobname is used for all kinds of things like aux files and having commas and spaces in file names is tricky. Just use pdflatex \def\mycommand{a,b,c}\input myfile possibly needing to quote the \ or {} depending on your commandline processor.


17

Here is a preliminary example (depending on what you are looking for) using a for loop, \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \def\repeatno{40} \node[inner sep=0.5cm,circle] (base) at (0,0) {}; \foreach \x in {1,2,...,\repeatno}{ \draw[rotate=(\x*360/\repeatno)-90] (base.\x*360/\repeatno) to [in=-70,out=70] ++(0,2) ...


16

One possibility is to use the xparse package: \usepackage{xparse} \NewDocumentEnvironment{mylist}{m}{% \begin{#1}% % other code }{% \end{#1}% }


16

You could use the xstring package \documentclass{article} \usepackage{xstring} \newcommand{\mymacro}[1]{% \StrLeft{#1}{1}[\firstletter]% \StrRight{#1}{1}[\lastletter]% First letter: \firstletter Last letter: \lastletter } \begin{document} \mymacro{ABCDEF} \end{document} I’m a little busy so please excuse that I didn’t build it in ...


15

I'm not sure to really understand the question. First I draw a closed curve and then I rotated this curve but there are no difficulty to do this, perhaps I'm on a wrong way! First curves : the closed curve is named \myclosedcurve \documentclass[11pt]{scrartcl} \usepackage{tikz} \begin{document} \def\spirographlike#1{% \def\repeatno{#1} \foreach \i in ...


14

There is more than one problem with such a definition. The \def instruction has the following syntax: \def<cs><parameter text><left brace><balanced text><right brace> where <cs> is the control sequence or active character to define; <left brace> and <right brace> stand for explicit braces (character tokens ...


14

Or in classic TeX; the following defines \fst and \lst to be the first and last characters (or be empty for short input) \def\fl#1{\flx#1\empty\empty\empty} \def\flx#1#2#3\empty{% \edef\fst{#1}% \edef\cdar{#2}% \edef\cddr{#3}% \ifx\cddr\empty \let\lst\cdar \else \expandafter\flxx \fi #3} \def\flxx#1#2\empty{% \edef\car{#1}% ...


13

The problem here is that the character must be already active when used for \def. The #1 argument however holds the same character in its previous catcode and this won't be affected by \catcode. There is a trick using \lowercase but I'm not sure if it works well with non-ASCII characters with normal LaTeX. You can use \scantokens (an eTeX extension ...


13

You can define recursive macros that call themselves until some termination is found; a solution to your problem can be as follows: \makeatletter % we need to use kernel commands \newcommand{\twoimages}{% \begin{figure}[!htb] \@twoimagesi } \newcommand\@twoimagesi{\@ifnextchar\stopimages{\@twoimagesend}{\@twoimagesii}} \newcommand\@twoimagesii[6]{% ...


12

\usepackage{newunicodechar} \newunicodechar{¼}{1/4} \newunicodechar{«}{<<} \newunicodechar{—}{---}


12

Here are 3 solutions using expl3, depending on your requirements. To perform the tests, I'd use \prg_case_int:nnn rather than an ad-hoc bunch of \ifthenelse statements: those are slower. (1) The simplest is to use \tl_head:n{#1} to access the first digit of the number, and \int_mod:nn {#1}{10} for the last one. This works for numbers less than 2^{31}, and ...


11

The trick storing the second parameter as macro and using it in the "end" part of the environment: \newenvironment{ctable}[2]% {% \def\ctablecaption{#2}% \begin{center}% \begin{tabular}{#1}% }% {% \end{tabular}% \captionof{table}{\ctablecaption}% \end{center}% }


11

The following example uses the syntax that the arguments are given inside the argument for the command: \images{{...}{...}{...}{...}{...}{...}...}. The macro \images then parses its argument and catches three arguments at a time: \documentclass{article} \newif\ifimagesSep \newcommand*{\images}[1]{% \par\noindent[begin images]\\\relax \imagesSepfalse ...


10

You can have a variable number of items by rethinking your usage of a tabular and using an inline list. \documentclass{article} \makeatletter \newcounter{inline} \def\inlinelist#1{% \setcounter{inline}{0}% \@for\next:=#1\do{% \stepcounter{inline}% \alph{inline})\thinspace\next\space} } \makeatother \begin{document} ...


10

I have a solution, though it's not quite what I had envisioned. From the answers (and lack of answers) I have come to believe that continuous rotations are not a built-in feature of tikz, so I took the suggestions of Jake and Altermundus to just program in all the math calculations myself using polar coordinates. Below is my solution and its output. % ...


9

Package gb4e makes the characters _ and ^ active. Their definitions disturb \includegraphics, where _ should be expandable and expand to itself. Either use \noautomath that resets the catcodes: \noautomath \includegraphics{Erg_Dat_Agree} Or \string that converts the next token _ to a character token with catcode "other" (12): ...


9

Using the environ package you can avoid the standard trick illustrated in Heiko's answer: \documentclass{article} \usepackage{capt-of} \usepackage{environ} \NewEnviron{ctable}[2]% {% \begin{center}% \begin{tabular}{#1}% \BODY \end{tabular}% \captionof{table}{#2}% \end{center}% } \begin{document} \begin{ctable}{cc}{test} test & test ...


9

You're trying to avoid floating tables, which is quite dangerous. Moreover you lose flexibility. However, if you really want to shoot yourself in the foot ;-), here's a possibility: the package xparse. \documentclass{article} \usepackage{xparse,capt-of} \NewDocumentEnvironment{ctable}{mm} % two arguments in braces {% begin part \begin{center} ...


8

The underlying idea here is to continuously rotate the paper whilst drawing the picture with TikZ. This is, of course, impossible. The difficulty with this is that the resulting path from doing this wouldn't (necessarily) be composed of lines and cubic bezier curves, which is all that PGF knows how to produce. But curves are really just lots of short ...


8

To scan a character at a time you need to use \futurelet (or its LaTeX wrapper \@ifnextchar) not a macro argument #1 then it is safe for {}. But for numbers I would just do this: \documentclass{article} \begin{document} \makeatletter \def\num{\afterassignment\xnum\count@} \def\xnum{the number was [\the\count@]} \num44 \emph{\num99} \end{document} ...


8

You have to define \dollarcom with a "stringified #": \documentclass{article} \usepackage{minted} \edef\dollarcom{\noexpand\mint{bash}/$\string#/} \begin{document} \dollarcom \mint{bash}|$#| \end{document}


7

It's not a definitive answer because I don't know how do you want to use this symbols and the code don't use conditioned styles. What I've done was to use pics (you need TikZ 3.0). The first pic clock draws the common part of your symbols and the other three pics use it (fixing its filling color) and draw particular characteristics. At the moment, each ...


7

As you correctly state, if all you need to do is store the user input, then a token list variable is the usual approach unless there is some 'structure' to think about. I would therefore define \NewDocumentCommand \myAssessments { O { I } O { cc } +m } { \tl_gset:Nn \g_myA_tl {#1} \tl_gset:Nn \g_myB_tl {#2} \tl_gset:Nn \g_myC_tl {#3} } ...


7

Try \StrRight in the xstring package: \documentclass{article} \usepackage{xstring} \def\getYear#1{\StrRight{#1}{4}} \begin{document} \noindent\getYear{12.12.2012}\\ \getYear{2012} \end{document} with result:


7

You can use the etoolbox to set up a boolean which is either true or false \newbool{hidetrafficlight} \setbool{hidetrafficlight}{false} and then depending on what value it takes, use \AtBeginEnvironment from the etoolbox to comment out the environment using comment from the verbatim package % set conditional behaviour of environment ...


7

Here is a key-value interface. I use skeyval package instead of pgfkeys only because I wanted to preset keys. \documentclass{article} \usepackage{skeyval} \usepackage{tikz} \usetikzlibrary{shapes.geometric} \makeatletter % Spurious spaces will appear in the following methods in horizontal % mode, but TikZ doesn't mind them. The star (*) form of \directkeys ...


7

You can avoid this error by modifying your class definition as follows: \ProvidesClass{UGentCourse}[2011/07/28 v1.0 UGentCourse] \DeclareOption{english}{\AtEndOfClass{\main@language{english}}} \DeclareOption{dutch}{\AtEndOfClass{\main@language{dutch}}} \DeclareOption*{\PassOptionsToClass{\CurrentOption}{book}} \ProcessOptions\relax ...


6

This depends on the font size selected for the document class or within the text and whether you're in \twocolumn or not (at least, for the default document classes). For the exact lengths, you need to view size10.clo, size11.clo, size12.clo in conjunction with the document class you're using. The following minimal example lists these totals for the various ...


6

The etextools package provides an expandable \ifempty{<text>}{<true>}{<false>} macro which works with newlines. If you don't need the test to be expandable you can also use the following code: \newcommand{\mymacro}[1]{% \begingroup \def\temp{#1}% \ifx\temp\empty \endgroup % empty \else \endgroup % ...


6

I do not know the purpose and format of the "number". There are many variants what can be considered a number: Explicit number consisting of digits 0 up to 9. TeX number, that includes count registers, internal numbers given by primitives (\inputlineno, \value{page}, \numexpr), even dimensions (\textwidth) can be interpreted as numbers. This solution ...



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