# Tag Info

9

You should be writing ## not \# in your macro: \documentclass{minimal} \usepackage{luacode} \newcommand{\Test}[1]{ \luaexec{ local x = string.gsub("#1", "##", "+") tex.print(x) } } \begin{document} \Test{With backslash: \#} % Throws an error as # is not processable in output \Test{Without backslash: #} % \end{document}

1

The following example call, \mysetpredicate, shows that you have to double up on the hashes. Four, for what will become two in the predicate itself to get the row number. Two, for what will become one to get the style parameter and one for the parameter to the wrapping function. I was surprised that I could just pass the file link in as is. I originally ...

1

No, it's not possible to do what you ask for, unless you completely change TeX's way of parsing input, examining token by token the text. However I'm afraid this would break infinitely many constructions of LaTeX. It might be possible with LuaTeX, but some expert's advice would be needed. Marking the input with a macro is the really practical way.

5

\tabcolsep is a length not a macro so it should be set using \setlength\tabcolsep{10pt} Not \renewcommand. You can set it anywhere before the table, if you set it in the document preamble it will apply to all tables in the document. If you want to affect just one table that you are inputting then you can do {\setlength\tabcolsep{15pt}\input{tablefile}} ...

1

You can't redefine \chapter in terms of itself. Use the internal version \@schapter which is called when \chapter* is issued. We have to take into account that \tableofcontents calls \chapter*, so an indirect call has to be made. \documentclass{report} \title{An Example} \author{Nobody} \makeatletter ...

3

You have a little hidden infinite loop. You are redefinying \chapter, which calls \chapter*. These are variants of the same command. Hence TeX builds a huge stack, ending with an overfull message.

10

Here's a laundry list of basic practices that are generally recommended. They all follow from the general principle for managing any complex software project: Take steps to keep the components as independent as possible, in their design ("loose coupling") and in their implementation. Protect the TeX namespace. Since TeX has only a single persistent ...

7

The Ejemplo part looks like it was set with colortbl and the Soluci\'on part with \colorbox Here is some code to produce those effects. Normally one would code examples with \newtheorem and one would have to go to some effort to make this automatic. But it is late, and I will leave that until later (or someone else can step in). I didn't try to match the ...

6

\newcommand{\egline}{% \par\vskip 1ex% % here you are in vertical mode {% %here you put a colour whatsit on the vertical list (best to avoid that if possible) \color{ejemplo}% % here you start a paragraph and get into horizontal mode \leavevmode % \hrule isn't allowed in hmode, so this ends the (blank) paragraph and gets back to vmode \hrule ...

17

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 ...

3


8

In fact, that's not so difficult. You just need to "pick up" the optional argument with a trick. See this example: \documentclass{article} \usepackage{amsmath} \usepackage{amssymb} \usepackage{xspace} \makeatletter \def\newmathcommand#1#{\@newmathcommand{#1}} \def\@newmathcommand#1#2{\newcommand#1{\ensuremath{ #2 } \xspace}} \makeatother ...

3

I'd use titlesec: \documentclass[a4paper]{article} \usepackage[margin=2cm]{geometry} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[brazil]{babel} \usepackage{titlesec} \titleformat{\section}[block] {\normalsize\bfseries} {} {0pt} {\MakeUppercase} \titlespacing{\section} {0pt} {4ex plus 1ex minus 1ex} {1ex} ...

1

From the comments above, I gather that you are not opposed to using different commands for each form that you want: you just don't want the hassle of having to write out the code each time you want to build a new declinable macro. Here's an approach which lets you build all the macros in one command that would closely resemble the typical \newcommand that ...

6

Just define a new environment. The simplest way is with the verbatim package: \documentclass{article} \usepackage{verbatim} \newenvironment{inverb} {\par\addvspace{\topsep}\noindent\textbf{In verbatim}\nopagebreak \verbatim} {\endverbatim} \begin{document} Something before \begin{inverb} some text \end{inverb} Something after \end{document} With ...

7


5

\documentclass{article} \usepackage{xspace} \newcommand{\mc}[1][]{\textbf{MyCommand#1}\xspace} \begin{document} \mc \mc[s] \mc['s]. \end{document}

3

Some slow scanning of the argument is needed: \documentclass{article} \usepackage{fixltx2e} % for \textsubscript \makeatletter \newcommand{\note}[1]{\emit@note#1\@nil} \def\emit@note#1#2\@nil{% \textup{#1}% \if\relax\detokenize{#2}\relax \expandafter\@gobble \else \expandafter\@firstofone \fi {\emit@@note#2\@nil}% } ...

18

The only quirk is that you have to use brackets [] rather than braces {} to enclose the argument. \documentclass{article} \def\note[#1#2#3]{#1\if b#2$\flat_#3$\else\if#2##$\sharp_#3$\else$_#2$\fi\fi} \begin{document} \note[Eb3] \note[A2] \note[F#4] \end{document} If you would prefer the use of braces to brackets, then the following modification would ...

8

You need to check the conditional when the macro is executed, not when it is defined. \documentclass{article} \usepackage{lipsum} \newif\ifABC \newcommand{\abcdef}[1]{\ifABC{Letters} #1\fi} \begin{document} \ABCtrue \abcdef{ABC} \lipsum[2] \end{document}%

2

Here's an implementation with l3regex; the number is stored in \l_linuxss_code_int for later usage. One can extend the testing by acting on the search regular expression; this one catches the letter or the character. \documentclass{article} \usepackage{xparse,l3regex} \ExplSyntaxOn \NewDocumentCommand{\getlettercode}{m} { \linuxss_getlettercode:N #1 ...

4

\Char is not expanded because it is not an expandable token. Unlike \def\Char{a} which expands to a \let defines a token that essentially is a and like a it does not expand. The only way to get hold of this in classic TeX is to take \meaning\Char which will be the letter a split that up on spaces, and if the first two words are the letter take the ...

10

As already mentioned in comments, the nag package does its best to pick up not only use of TeX rather than LaTeX syntax but also deprecated LaTeX stuff. That is the best you can do with LaTeX2e because of the way the kernel itself and packages are written: they use TeX constructs without 'LaTeX wrappers'. One of the aims of the LaTeX3 Project is to develop ...

9

too late to worry too much about spacing but this does the section levels and the paragraph counting, it takes two passes to get the paragraph counts for each clause. b.cls \LoadClass[a4paper]{article} \RequirePackage[utf8]{inputenc} \def\maketitle{% \begin{center}\large\bfseries\@title \end{center}} ...

2

This is not a complete answer but perhaps somebody else can finish it. Do you want something like the following? \documentclass[a4paper]{article} \usepackage[T1]{fontenc} \usepackage{textcomp} \usepackage[utf8]{inputenc} \usepackage{enumitem} \newlist{contrato}{enumerate}{2} \setlist[contrato,1,2]{wide,,labelindent=0pt} \setlist*[contrato,1]{label={Cláusula ...

6

rather than worry about utf-8 it's probably best to let inputenc worry about that and expand all characters to LICR (latex internal form) then you would also be able to support [latin1] or anything else. I also changed \if it \ifx as \if looked wrong (although I don't really know what the code is doing:-) \documentclass{article} ...

-2

I will try to answer the question "is there a way to make the LaTeX compiler and TexStudio (Or another editor) not use the TeX commands in order to preserve proper typesetting?" To stop $from working, you can insert, just before \begin{document}: \catcode\$=11 (I tested this on my current draft[1], which still compiles normally to its 14 pages). This ...

8

Where did you "learn" that using $as a switch to initiate and terminate inline math mode is incorrect for LaTeX users? I'd go even further than @egreg does in his comment and state that not only is using$ to start and end inline math mode not wrong, it has certain advantages over $$and$$. Consider the following MWE: \documentclass{article} ...

10

This is not basically possible, and I'll try to explain why, on an example. Let's \show\section: \section=\long macro: -> \@startsection {section}{1}{\z@ }{-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus .2ex}{\normalfont \Large \bfseries } Ok, not much to see, other than that \section takes no arguments at all! So let's \show\@startsection: ...

12

In general, there is no starred version of a command. What really happens is that the unstarred command checks to see if there is a star as the first argument and passes control to different auxiliary macros accordingly, or simply executes two different sets of commands. So, to take a random example, we look at \endlargethispage and find that it is defined ...

8

\psdot expands its argument, but \numexpr is not expandable; it expands after \number or \the. In the context of a \numexpr it's better to use \value{mycnnt}, that refers to the “abstract” value, instead of \themycnt that refers to its representation. \documentclass{article} \usepackage{pst-node} \newcounter{mycnt} \setcounter{mycnt}{2} ...

7

The character maps of T2A and T1 are identical in the first 128 positions. So english texts should work fine with T2A. But if you want to insert umlauts and other accented chars from the upper part of the char table of T1-encoding you should consider to switch to T1 for such texts instead of relying on LaTeX to fall back to the correct definitions.

2

There's an obvious error in the definition of \pfc, which however doesn't seem a really useful command by its own. You get a simpler implementation by fully using expl3: \documentclass{memoir} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{xparse,xspace} \ExplSyntaxOn \NewDocumentCommand{\D}{ o } { \IfNoValueTF{#1} {% No optional ...

10

The respective TeX code is @<Compute the hash code |h|@>= h:=buffer[j]; for k:=j+1 to j+l-1 do begin h:=h+h+buffer[k]; while h>=hash_prime do h:=h-hash_prime; end So basically each digit gets mapped to some 2^k mod p. Prefixes and postfixes don't actually make the hashing worse, but the somewhat peculiar structure of the hash table means ...

8

You have defined it as a command taking no arguments but used #1 in the definition so get an error, just as you would with \newcommand or \def. To pass the argument of the outer command on to \pfc you need to define \pfc as a macro taking one argument and then use \pfc{#1} in your second definition, to pass that argument on. So ...

6

In latex internal code, any command that can be used in a paragraph, but provides no visible text, uses two internal commands: \@bsphack and @esphack. The first one tries to detect if a space preceded it and passes that information to the second. If the space was there \@esphack issues \ignorespaces. Thus: \documentclass{article} ...

3


0

The syntax to create a new environment is \newenvironment{<name>}{<begin-doce>}{<end-code>} What you want cane achieved as \newenvironment{myitemize} {\begin{itemize}\item} {\end{itemize}} I suggest to load enumitem package. It has feature to create series, to suspend continue numeration from different list environments, and to ...

5

An interesting example of how one can define commands with different syntax, but doing the same thing, with minumum effort. \documentclass{article} \usepackage{xparse} \ExplSyntaxOn % Define the keys \keys_define:nn { jeroen/add } { title .tl_set:N = \l_jeroen_add_title_tl, title .initial:n = {}, entity .tl_set:N = \l_jeroen_add_entity_tl, ...

3


7

I'm going to suggest a very different approach which might seem like a bit of overkill in this particular situation but can pay off in the long run. I would suggest using keys to accomplish what you want. So, I would set up keys as follows: \documentclass{article} \usepackage{pgfkeys} \makeatletter \pgfkeys{/jeroen/entities/.cd, title/.initial=, ...

4

xparse can save life with its features some times. Here is an example: \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\Add}{mm}{\textit{#1}{} #2'} \begin{document} \Add{article}{\LaTeX} \end{document} For details texdoc xparse or visit texdoc.net

10


0

5

You have loads of unprotected end-of-lines that could produce a space in output. \documentclass[12pt]{article} \usepackage[nomessages]{fp} \usepackage{color} \usepackage{wrapfig} \usepackage{amsmath} \usepackage{ifthen} \newcommand{\ticks}[5]{%x,y,numticks,direction (x=0,y=1),tickwidth \ifthenelse{#3=0} {}% {% \ifthenelse{#4=0} {% ...

5

Put \color{mylinecolor} inside: \newcommand{\drawthedamnline}[1]{% %% <---Spurious space %\color{\mylinecolor} \put(\mypeakx, \peaky){\color{\mylinecolor}\line(1,#1){\peakspace}} } Full code: \documentclass[12pt]{article} \usepackage[nomessages]{fp} \usepackage{color} \usepackage{wrapfig} \usepackage{amsmath} \usepackage{ifthen} ...

4

The comment environment (comment package) should start in a new line without a space before. From the manual: The opening and closing commands should appear on a line of their own. No starting spaces, nothing after it. Otherwise it won't work and cause strange errors.

12

Usually, spaces at the beginning of a line are ignored by TeX. However, this is not the case when writing in a verbatim like context. The same is true for tabulators. Whitespace characters like NO-BREAK SPACE (U+00A0) behave in a different way. To use them properly, a modern engine like LuaLaTeX in conjunction with fontspec is needed. Please be aware, ...

2

An update (v. 0.37, 2013/11/27) of media9 is on the way to CTAN which will cope with this.

3

Please, never try to "get rid of the 'additional dollars'." First, you easily mis-interpret your math as text. Second, this then leads to doing things like \varn=0, which, in text mode, becomes $p^{i,j}_{t}$=0, and this get completely wrong spacing. So, you should define \newcommand{\varn}{p^{i,j}_{t}} and then use it as in: We have that $\varn=0$ if and ...

Top 50 recent answers are included