Tag Info

New answers tagged

0

I can see the problem. You are using a "/" which is only to indicate the image is in a subfolder. The code to positioning the cursor it's just conformed by %<%>. Creating a macro for inline math code, it look like $ %<%> $ Inclusive, you can include text inside it, like a tag for reference: $ %< tag %> $ If your macro has more than one cursor ...


2

A. Ellett's suggestions are good, but there are some subtleties connected with this approach. Localizing the definition with \bgroup and \egroup is bad, because the \set macro is clearly used in math mode. Such a construction would make a subformula, with the consequence that spaces are frozen and don't participate with stretching and shrinking on the ...


5

You can define a command as \newcommand\set[1]{%% \begingroup \def\suchthat{... some definition...}%% ... other macro content .... \endgroup} And this will make \suchthat available inside the macro. You could have done this with \bgroup and \egroup, but that creates a subformula with consequences on how the spacing is handling if used in ...


1

First of all, your intend can be realized simple by setting \endlinechar=-1. You needn't to set catcode for ^^M because \endlinechar-1 causes that this character isn't inserted. You needn't to set catcode for ^^I (tab) because spaces and tabs have catcode 10 and they are simply ignored at the beginning of each line. But this setting is dangerous. Of ...


0

The comment package provides a mechanism to do this via \specialcomment and \excludecomment.


3

You can easily do that with the accents package: \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{mathtools,amssymb} \usepackage{accents} \newcommand*{\uhat}[1]{\underaccent{\hat}{#1}} \newcommand*{\uwidehat}[1]{\underaccent{\widehat{\hphantom{#1}}}{#1}} \begin{document} $ \uhat{x}\enspace \uwidehat X$ \end{document}


1

For the under hat just use \underaccent{\check}; for the wide under hat, typeset the wide hat over a phantom of the argument, then flip it vertically, raising it by a suitable amount. Then overlap the flipped accent to the text. \documentclass{article} \usepackage{amsmath} \usepackage{accents} \usepackage{graphicx} \newcommand{\uhat}{\underaccent{\check}} ...


1

This won't work. \citet is a much to complicated macro, you can't retrieve its output is a simple way. If you really want to stick to natbib (in biblatex language support is build in) you should manipulate the .bst-file. Save it under another name in your document folder and then change the fixed words so that they issue commands. E.g. FUNCTION{fr.and}{ ...


3

Package acronym The internal expandable version of \acl is \AC@acl. Then \index inside the macro \acidx will write the expanded long version of the acronym: \documentclass{article} \usepackage{acronym} \usepackage{makeidx} \makeindex \makeatletter \newcommand*{\acidx}[1]{% \ac{#1}\index{\AC@acl{#1}}% } \makeatother \acrodef{ABC}{alphabet} ...


3

You can use the csquotes commands - they even work with utf8 chars where you can't use directly the \catcode trick from David. The main problem is to choose the chars so that you don't get side effects on the rest of your document. \documentclass{article} \usepackage[utf8]{inputenc} \usepackage{csquotes,xcolor} \makeatletter ...


3

\catcode`*\active \def*(#1)*{\incise{#1}} makes *(xxxx)* act as you like, as long as you don't use * anywhere else....


3

Put \width inside braces. The space after \width is swallowed to give 2and which should be 2 and. \documentclass[12pt, a4paper]{article} \usepackage{amsthm, tikz} \usetikzlibrary{arrows, shapes, trees, positioning} \begin{document} \begin{figure} \centering \begin{tikzpicture} \newcommand*{\width}{2}% \newcommand*{\height}{0.5*\width}% ...


6

It is exactly an expansion problem. Here's the definition of \NewDocumentCommand: \cs_new_protected:Npn \NewDocumentCommand #1#2#3 { \cs_if_exist:NTF #1 { \__msg_kernel_error:nnx { xparse } { command-already-defined } { \token_to_str:N #1 } } { \__xparse_declare_cmd:Nnn #1 {#2} {#3} } } It would be very easy to ...


4

l3 allows you to avoid \expandafter \documentclass{article} \usepackage{xparse} \newcommand{\standardargs}{O{}+m} \ExplSyntaxOn \def\MyNewDocumentCommand{\exp_args:NNo\NewDocumentCommand} \ExplSyntaxOn \MyNewDocumentCommand{\somecmd}{\standardargs}{% % Do something more or less useful My args: #2 } \begin{document} \somecmd{Hello World} ...


4

Yes, expand the macro before \NewDocumentCommand tries to grab the second (macro definition) argument: \documentclass{article} \usepackage{xparse} \newcommand{\standardargs}{O{}+m} \expandafter\NewDocumentCommand\expandafter\somecmd\expandafter{\standardargs}{% % Do something more or less useful My args: #2 } \begin{document} \somecmd{Hello World} ...


2

Here's a possible implementation: \documentclass{article} \usepackage[T1]{fontenc} \usepackage{textcomp} %\usepackage{libertine} \usepackage[dvipsnames]{xcolor} \usepackage{xparse} \ExplSyntaxOn % user level commands \NewDocumentCommand{\meta}{O{}m} { \pablo_meta_generic:Nnn \pablo_meta:n { #1 } { #2 } } \NewDocumentCommand{\marg}{O{}m} { ...


1

I do not recommend this, but for the sake of completeness, a macro name with a single non-letter character do not gobble the spaces after the macro: \documentclass{article} \def\æ{Arnold Schwarzenegger} \begin{document} \æ is an actor. \end{document}


4

\unskip removes previous space. Depending on the mode this is horizontal or vertical space. Spaces after the command can be ignored by \ignorespaces. A space token can be set by \space and \@ifnextchar tests for following tokens to avoid space setting, if a punctuation character follows. As side effect it also removes following spaces. Full example: ...


0

Idea: Instead of writing a command that does some funny stuff to detect whether \global or another prefix came before, modify \global etc. to look ahead and use a protocol to inform the appropriate macro that it is to consider itself prefixed. The following is not working code and is intended to suggest an approach \let\ea\expandafter \makeatletter ...


8

You can do it with \aftergroup: \documentclass{article} \protected\def\defun{\aftergroup\newdefun\aftergroup{}} \newcommand\newdefun[1]{\fbox{#1}} \begin{document} \tableofcontents \section{Here {\defun SomeFunctionName arg1 arg2}} Call {\defun SomeFunctionName} to foo the bar. \end{document} The same limitation as David Carlisle's answer holds: ...


10

My preferred approach would be: use the find-and-replace function of your editor of choice and replace {\defun with \textdefun{. EDIT: As @Clément points out, this does not work in cases like \section{\defun abc def}. I am afraid those cases would elude even a more sophisticated regexp-based approach, because one would have to add an additional closing ...


1

This is uses in fact three optional arguments: \ME[operation driver]<operation argument>[operation comment] Any of them can be omitted, in this case nothing would happen. \documentclass{article} \usepackage{changes} \usepackage{xstring} \usepackage{xparse} \definechangesauthor[name={MyName},color=blue]{ME} \DeclareDocumentCommand \MEOrig{ o m }{% ...


18

\documentclass{article} \protected\def\defun{\expandafter\zdefun\expandafter{\iffalse}\fi} \def\zdefun#1{A \fbox{#1} B\egroup} \begin{document} \section{\defun SomeFunctionName arg1 arg2} Call {\defun SomeFunctionName} to foo the bar. \end{document} Here \iffalse}\fi expands to nothing so \expandafter{\iffalse}\fi expands to a single ...


3

Font switches such as \itshape, \mdseries and \scshape tell LaTeX to switch to a different font. The font LaTeX switches to depends on the currently active family, and the various fonts corresponding to the different attributes (weight, shape etc.) are usually defined in a font definition file. Simplifying reality somewhat, when you say \itshape this is ...


9

Yes, there is a better way: \usepackage{xparse} \NewDocumentCommand{\mychapter}{som}{% %%% things to do before \chapter \IfBooleanTF{#1} {\chapter*{#3}} {\IfNoValueTF{#2}{\chapter{#3}}{\chapter[#2]{#3}}% %%% things to do after \chapter } This supports all three calls: \mychapter*{Title} \mychapter{Title} \mychapter[Short title]{Long title} ...


8

The traditional way, before xparse allowed for more flexible solutions, is to use \@ifnextchar[ to check for the [ of the optional argument and to inject other code into the wrapper. The starred version is included as well and can have an [] now as well -- it's up to the OP to decide what this [] should do then ;-) \documentclass{book} ...


1

The following answer is based on http://tex.stackexchange.com/a/58512/36296 and the author definition in latex.ltx main.tex \documentclass{beamer} \usetheme[myText=Hello World!]{tudrobert} \author{George Orwell} \title{Animal Farm} \date{\today} \institute[TUD] \def\uni{Hello World!} \begin{document} \begin{frame} \titlepage \end{frame} \end{document} ...


5

The box is quite deliberately never used. The idea here that that \beamer@@@temp might contain material that gets typeset. Carried out inside a box, anything that does end up typesetting material causes no problem inside the document as the box is thrown away. All that is needed after this code is the results of the decoding, which are set globally so are ...


1

Well, the error is quite clear: the code \begingroup\edef\x{\endgroup\noexpand\lstinputlisting[label=#4, name=#4] {#2} {\ME@decorations} % Decorating comments }\x should be \lstinputlisting[label=#4, name=#4] {#2} \ME@decorations % Decorating comments There's absolutely no reason for using the \edef\x trick here and the problem is exactly that ...


3

xunicode sets up for these commands also some OT1 defaults, but the main point are accents commands. E.g. \DeclareEncodedCompositeCharacter{\UTFencname}{\M}{0322}{0322} % (Combining retroflex hook below) You can naturally redefine the command if you don't use it, but there is a tradition to use "one-char-commands" for accent commands and so I would never ...


3

If you want the macro without the optional argument: \documentclass[a4paper,10pt]{article} \newcommand{\macro}[2]{% notice the lack of the second brackets here & something & #2 & #1 \\ } \begin{document} \begin{tabular}{lccc} \macro{3}{4} \end{tabular} \end{document}


6

The macro \macro (sic!) is defined to have an optional argument. If this missing, the call \macro{3}{4} is the same as \macro[]{3} and the figure 4 will be read for the next tabular row. The column shift in the 'wrong' usage is clearly visible. 3 is in the 4th column, instead of the requested 3rd column. \documentclass[a4paper,10pt]{article} ...


5

A simpler solution using expl3 and its powerful fp module. \documentclass{article} \usepackage[table]{xcolor} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand{\he}{m} { \cellcolor[gray]{ \fp_eval:n { min ( 2*#1, 1 ) } } #1 } \NewDocumentCommand{\hetest}{m} { \cellcolor[gray]{ \fp_eval:n { min ( 2*#1, 1 ) } } \textcolor{red}{#1 ~ -- ~ ...


6

The following example solves the issue by expanding \resa before \cellcolor is expanded and looks at its arguments. The second problem is, the range for the color model gray is between 0 and 1 inclusively. The values 0.8 and 1.0 exceed this, when multiplied by 2. Therefore the example checks the result and limits it to 1 if necessary. ...


6

You could add the line \xdef\resa{\resa}%% to your code. But things still won't compile properly because your multiplier gets you out of the range from 0 to 1. \documentclass{article} \usepackage{fp,xcolor,colortbl} \FPeval{\resb}{0.5} \newcommand{\he}[1]{% \FPeval{\resa}{2 * #1}% \xdef\resa{\resa}%% \cellcolor[gray]{\resa}% #1 } ...


3

Similar to A.Ellett's answer: Switch the category code of % from "comment character" to "other" and back again: \documentclass{article} \makeatletter % Switch catcode for % to other \newcommand{\rtext}{% \catcode`\%=12 \@rtext} % Switch catcode for % back to comment character \newcommand{\@rtext}[1]{\texttt{\detokenize{#1}}\catcode`\%=14} ...


5

You can do some catcode magic. The general idea is as follows \documentclass{article} \makeatletter \newcommand\detokenizeWithComments{%% \bgroup \catcode`\%=12 \ae@detokenize@with@comments } \def\ae@detokenize@with@comments#1{%% \detokenize{#1}%% \egroup} \makeatother \begin{document} Hello world \detokenizeWithComments{This ...


2

without evidence to the contrary, \hip appears to be a "fragile" command. adding \protect before a fragile command in a "moving argument" (the argument to a command like \paragraph that can potentially also be used somewhere else, such as in the toc) will avoid the problem. so here, \protect\hip. more information on this situation can be found with the ...


0

The issue was solved by using \protect, as suggested by @barbarabeeton. If she posts an answer I'll be happy to remove this and accept hers :) \paragraph*{\protect\hip{} Following...} On @qzx's answer and @cfr's & @Werner's comments: I didn't add a preamble because mine's way too big, and I thought it wasn't an issue with it. It might be ...


3

Sure, why not. Your use, your choice. Depending on the specific application, you might consider using \xdef take make the (expanded) redefinition global or \protected@xdef to accommodate "strange constructions" in names...


5

I would use different commands, one to hold the name and another to set the name. In a package, it is a common practice to use an external version of the command (\name) to set the value of an internal macro (\@name). This is how \author and \title work in the article class. \makeatletter \newcommand{\name}[1]{\gdef\@name{#1}} \makeatother But it would ...


0

Commands cannot (usually) contain numbers. Try defining No or NO (those are the letter 'o' in lower and upper case) instead. In my preamble I have defined \NNo for \mathbb N_0 for example.


2

It seems like this is also a situation where \scantokens could come in nicely: \documentclass[a4paper]{scrreprt} \newcommand{\cmd}{\begingroup \catcode`_=12 \cmdint} \newcommand{\cmdint}[1]{% \texttt{\scantokens{#1\noexpand}}% \endgroup } \newenvironment{wrap}{}{} \usepackage{environ} \NewEnviron{wrap2}{\BODY} \begin{document} \cmd{some_test} ...


1

The solution depends on the alphabet, used for the variables. If these are identifiers with upper and lower case letters, digits, underscore and some other harmless symbols (with category code 12/other, as punctuation chars) then \detokenize can be used to normalize the category codes of the identifier to token with category code 12 (same as digits): ...


3

Your \listLength command doesn't work by pure expansion; you should say \newcommand*{\listLength}[1]{% \setcounter{listlength@cnt}{0}% \forcsvlist{\listlength@add}{#1}% } as the definition of \listLength and then \listLength{\@glo@types}% \addtocounter{mtc}{\value{listlength@cnt}}% in the code. There's a much slicker way with expl3: ...


4

The example in the question reveals quite some show stoppers: Package graphics needs to know the file name extension and calls LaTeX's \filename@parse to split the path specification. \filename@parse expands the first token once. Thus it is possible to put the starting path in a macro. But after the expansion step, further macros or nested macros are not ...


0

As suggested by Jojo Boulix in the comments beamer options are the way to go. The three files could then look like: main.tex \documentclass{beamer} \author{George Orwell} \title{Animal Farm} \date{\today} \institute[TUD] \usetheme[location=Berlin]{tudrobert} \begin{document} \begin{frame} \titlepage \end{frame} \end{document} ...


5

You can also do it with latex or pdflatex, by using the packages fontenc (encoding for the printed text) and inputenc (encoding for the source file). \documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \begin{document} àâéèêîôùû \end{document} You can see this question for more details.


4

Don't. Just don't typeset é as \'e, if you need lots of them. Typeset them as é using your French keyboard, store the file as utf-8, and compile with a Unicode-aware TeX engine like xelatex. See, however, the comments below the answer of T. Verron: xelatex is not the standard engine. Therefore you might prefer a solution that works with pdflatex.


3

Due to how you defined \lowsc, the redefinition in the header applies to nothing, because what TeX sees at that point is not \lowsc any more, but \scalebox{0.8}{i}. Using \DeclareRobustCommand for \lowsc solves the problem. I'd use a conditional, however. \documentclass{scrreprt} \usepackage[markcase=lower]{scrlayer-scrpage} \usepackage{graphics} ...



Top 50 recent answers are included