Tag Info

New answers tagged

2

Here is an example of using mdframed to highlight the answer portion: References: You might want to try some of the other alternatives in Environments for visually setting text apart Code: \documentclass[12pt]{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage[english]{babel} \usepackage{microtype} ...


6

I would strongly recommend against this, but it can be done. The command \  is a primitive meaning 'a normal space' so shows up in various places, in particular the definition of \nonbreakspace. Thus a 'safe' redefinition of \  must at least deal with that: \documentclass{article} \let\hardspace\ % ...


0

For example, starting from the definition of ~: \makeatletter \def\hallospace{\penalty\@M \kern0.3em} % say, 0.3em \let\oldspace=\ % \let\ =\hallospace \makeatother (And remember to use ~ as an unbreakable space in the future).


0

This one uses matrix \documentclass{article} \usepackage{tikz} \usetikzlibrary{matrix} \tikzset{ table/.style={ matrix of nodes, row sep=-\pgflinewidth, column sep=-\pgflinewidth, nodes={rectangle,minimum size = 1cm,align=center,inner sep=0pt}, text depth=1.25ex, text height=2.5ex, nodes in empty cells }, } \begin{document} ...


3

If you are really doing a picture (although your example sure looks like a table), then probably is best done to use a modern drawing package such astikz: Code: \documentclass{report} \usepackage{tikz} \newcommand*{\NodeWidth}{1.0cm}% \newcommand*{\NodeHeight}{1.0cm}% \tikzset{My Node Style/.style={rectangle, ultra thick, minimum width=\NodeWidth, ...


1

Have a look at Koma-Script package scrdate. Documentation of Koma-Script, look for scrdate Example Commands: \DayName{year}{month}{day} \ISODayName{ISO-date} \ISOToday \todaysname \todaysnumber


3

\the\day--\the\month--\the\year In case you want a verbose month, I think it's done in LaTeX with \ifcase\month\or January\or February\or March\or April\or May\or June\or July\or August\or September\or October\or November\or December\fi (Not sure if I wrote them correctly)


1

Go to View > Messages Pane: Then click on the "Settings" tab in the bottom right corner: Then click on the "Selected" radio button: Then double click on "User commands" so that "no" turns to "yes": Then click on the "Output" tab: Then do the action that you want to copy the shortcut of. In this case, insert your horizontal line. In the output ...


1

The standard way to make an “invisible” command is to use \@bsphack at its beginning and \@esphack at the end. \documentclass{article} \usepackage[usenames]{xcolor} \usepackage[normalem]{ulem} \def\Corrections{2} % Highlight or Final - 1 or 2 \ifnum\Corrections=1 % 1 - Highlight \newcommand{\xcut}[1]{{\color{red}{\sout{#1}}}}% ...


1

The lines %\setlength{\maxdepth}{0pt}% to address the "third bug" %\setlength{\topskip}{0pt}% no space above the first line %\vspace*{\dimexpr0.000cm-\topskip plus 1fill} Can't ever do anything very helpful to the document and if I remove them the first page is the expected size.


3

Without putting much thought into it the first to try would be \newcommand\xcut[1]{\ignorespaces}


4

The prefix \global can only go in front of an assignment. However, TeX expands tokens after \global in order to find the assignment. An example is the \booltrue macro in etoolbox: \newrobustcmd*{\booltrue}[1]{% \ifcsundef{if#1} {\etb@noglobal\etb@err@nobool{#1}} {\csname#1true\endcsname}} If one does \global\booltrue{foo}, the latter macro is ...


5

I'd just use a "helper" macro so the \savedstyle can be expanded (once): \documentclass[varwidth,border=5]{standalone} \usepackage{tikz} \usetikzlibrary{arrows.meta} \newcommand{\misdirection}[2][]{% \begin{tikzpicture} \node (tree) at (0,0) {tree}; \node (apple) at (3,0) {#2}; \draw [blue,#1] (tree) -- (apple); ...


4

With expl3, just for fun :) \documentclass{article} \usepackage{xparse} % automatically loads expl3 \usepackage{tikz} \usetikzlibrary{arrows.meta} \newcommand{\misdirection}[2][]{% \begin{tikzpicture} \node (tree) at (0,0) {tree}; \node (apple) at (3,0) {#2}; \draw[blue,#1] (tree) -- (apple); \end{tikzpicture}} \ExplSyntaxOn % Declare our ...


1

Here's how to do it without expl3: \newcommand\freezeStyle[1][]{% \pgfqkeys{/demo}{#1}% \expandafter\edef\csname\savedname\endcsname##1{% \noexpand\misdirection[\savedstyle]{##1}}} Note that \edef is used here and \noexpand is used to protect macros that should not be expanded. \typeout{\meaning\helloMom} macro:#1->\misdirection [execute ...


0

If I understand your question, you need to interpret every paragraphs (separated by blank line) as a section title if such paragraph preceedes exactly two blank lines. You can try this: \def\par{\endgraf\futurelet\next\parA} \def\parA{\ifx\next\par \expandafter\sect\fi} \long\def\sect#1#2\par{\bigskip{\bf #2}\par\nobreak\medskip} block of text section ...


3

While it is certainly possible (and maybe also fun) to do such transformations in (La)TeX directly, I would just employ perl or a similar tool that supports search & replace across multiple lines. In your case: perl -0777 -i.bak -pe 's/\n\n\n(.*)\n\n/\n\n\\section{\1}\n/' plain.txt will transform the file text.txt accordingly. Some details: The ...


0

With Notepad++, use the extended search mode and look for three return to line you entered (two empty lines) using \r\n\r\n\r\n Replace it by \r\n\r\n\r\n\section{ close the \section command by knowing that \r\n\r\n" follows. Replace \r\n\r\n" by }\r\n" You will then transform "lorem ipsum dolor sit amet." (A block of text.) Title "lorem ...


1

Step1 : you must have installed miktex first Step2 : When you install texnic center in windows 7/8 all configuration will be set Step3 : otherwise manually you can set the path by going into Build ->> define output profiles and set the correct compiler.


2

Another way is to use the psmatrix environment, from pst-node. The objects are firstdescribed as nodes in a matrix, then the arrows are described. In this description, nodes can be given a name, or are described by their pair of indices i, j in the matrix. See documentation of pst-node for details on how to connect nodes or more generally how to fine-tune ...


1

Do you want this? \documentclass[a4paper,11pt]{report} \DeclareMathAlphabet {\mathbfit}{OML}{cmm}{b}{it} \usepackage[T1]{fontenc} \usepackage[utf8x]{inputenc} \usepackage{lmodern} \usepackage{amsmath} % \newcommand{\vect}[1]{\vec{#1}} \newcommand{\vect}[1]{\boldsymbol{\vec{#1}}} \begin{document} \begin{gather} \rho = \rho _{0}(\vect{x} , t) + ...


0

Instead of \lstnewenvironment{whatever} { \lstset { \stringlstset, language = whatever, ... } } you can \lstnewenvironment{whatever} { \expandafter\lstset \expandafter{ \stringlstset, language = whatever, ... } }


6

The second argument of \lstnewenvironment is just arbitrary code to execute before the environment. It can therefore consist of several \lstset commands, and you can put your common customisations in to one command, say \stringlstset, that is a \lstset in its own right. Here is a small example: \documentclass[a4paper,12pt]{book} \usepackage{listings} ...


2

The package mathpartir defines \snoc inside the mathpar environment, overriding whatever definition you give outside. Yes, it is a reserved command, although I couldn't find any trace of this in the documentation.


1

You can put expanded value of the register to the macro \m. No matter if eTeX is used or isn't, because we needn't to use \dimexpr. \def\m#1{{ \dimen0=200pt \#1=#1 % Outputs 200pt rather than 100pt }} \dimen0=100pt \expandafter\m\expandafter{\the\dimen0}


2

If I understand what do you need, you plan to write a macro \makefunc which does following: \makefunc \hello A1 \makefunc \goodbye B2 \hello X % -> XA:1 \hello Y % -> YA:1 \goodbye X % -> XB:2 \goodbye Y % -> YB:2 This could be done by only one line of definition: \def\makefunc#1#2#3{\def#1##1{##1#2:#3}} Note that there is no ...


1

If you use e-TeX, you can avoid using a register, exploiting the fact that \dimexpr is essentially a nameless dimension register: \def\m#1{\expandafter\minner\expandafter{\the\dimexpr#1\relax}} \def\minner#1{{\dimen0=200pt \#1=#1}} The input \dimen0=100pt \m{\dimen0} will produce #1=100.0pt Without e-TeX and \dimexpr, the workaround is to reserve a ...


5

Macro delimiter braces have to be explicit catcode 1 and 2 characters, (typically {}) they can not be \bgroup\egroup. You can do \documentclass{article} \usepackage{ifthen} \newcommand{\var}{1} \newcommand{\ABSTRACT}[1]{\begin{abstract}#1\end{abstract}} \begin{document} \ifthenelse{\var = 1} {\newcommand\myabstract[1]{\ABSTRACT{#1}}} ...


8

You can use \bgroup and \egroup to begin and end groups in such circumstances. \documentclass[11pt,a4paper]{article} \newcommand\test{sheep \egroup} \begin{document} Pig \bgroup\Huge\test goat \end{document}


4

If all that is needed is to obtain the appropriate macro name, there is no need for any tests at all, as things can be done using \csname \newcommand\makefunc[3]{% \expandafter\def\csname #2\endcsname##1{% \csname myobject##1#1\endcsname{#3}% }% } This will work even with more complex names as you can simply use a \cnsame definition for you ...


3

Your problem is not the square brackets: it's the definition of the matrix environment. If you do \show\matrix you get > \matrix=macro: #1->\null \,\vcenter {\normalbaselines \m@th \ialign {\hfil $##$\hfil &&\quad \ hfil $##$\hfil \crcr \mathstrut \crcr \noalign {\kern -\baselineskip } #1\crcr \mathstrut \crcr \noalign {\kern -\baselineskip ...


5

You should see your mistake when you compile the following document body: \makefunc{A}{hello}{1} \hello{X}\\ % XA:1 \hello{Y}\\ % YA:1 \makefunc{B}{goodbye}{2} \goodbye{X}\\ % XB:2 \goodbye{Y} % YB:2 The output is as you want it. The reason for that is because when you create your function \hello (via \makefunc{A}), the internal definition requests ...


3

Renewing a command with the command itself in its definition won't work because TeX doesn't remember what the command was previously as you're redefining it. The code you're looking for is something along the lines of: \documentclass[12pt, letterpaper]{article} \usepackage{relsize} \let\RightArrow\rightarrow ...


5

Similar to Werner's approach but using expl3: \RequirePackage{expl3} \ExplSyntaxOn \clist_map_inline:nn { one , two , three , four } { \keys_define:nn { mycmd } { #1 .tl_set:c = { l__mycmd_ #1 _tl } } } \cs_new_protected:Npn \MyCommand #1 { \group_begin: \keys_set:nn { mycmd } {#1} Key~values~are: \clist_map_inline:nn { one ...


5

My answer is only Werner's answer by another tools: instead of usage of xkeyval, there are five lines of code with TeX primitives. The result is exactly the same as Werner's result. \def\kv#1{\expandafter\ifx\csname kv:#1\endcsname \relax \expandafter\kvunknown \else \csname kv:#1\expandafter\endcsname\fi } \def\kvunknown{???} \def\kvscan ...


7

This is also an answer to this How to define a macro which does not read the next token after itself? question, hence two variants of definition. * is here a character that will never be a true argument. \documentclass{article} \begin{document} %\newcommand{\ACROeg}{e.\,g.} \def\ACROe*{e.\,g.} This is a sample sentence, \ACROe* it does not make much ...


6

I would suggest creating a number of keys that the user can decide to use or not. It also allows them the freedom to specify only a portion of them, in any order they wish. Here's a quick example using xkeyval: \documentclass{article} \usepackage{xkeyval} \makeatletter % ========= KEY DEFINITIONS ========= \define@cmdkey{mycmd}{one}[one]{} ...


3

I don't know in what sense this is useful, but here's an option with xparse. \documentclass{scrartcl} \usepackage{xparse} \ExplSyntaxOn \NewDocumentCommand \mycommand { g g g g g g g g g } { \seq_clear:N \l_tmpa_seq \IfValueT { #1 } { \seq_put_right:Nn \l_tmpa_seq { #1 } } \IfValueT { #2 } { \seq_put_right:Nn \l_tmpa_seq { #2 } } \IfValueT { #3 } ...


1

You can use \addto macro by the following way: \long\def\addto#1#2{\expandafter\def\expandafter#1\expandafter{#1#2}} \def\addtolist#1{\global\addto\totcontent{, \texttt{#1}}} \newread\infile \openin\infile=test-2.txt \bgroup \endlinechar=-1 \gdef\totcontent{}% \loop \unless\ifeof\infile \read\infile to\tmp \ifx\tmp\empty \else ...


2

The usual problem are the end of lines. You don't want \readline, but the normal \read. \begin{filecontents*}{\jobname.txt} some more words in here so as to eventually print \end{filecontents*} \documentclass{article} \makeatletter \newread\myread \makeatletter \def\strip@final@space{\expandafter\strip@final@sp@ce\@tempa\strip@final@sp@ce} ...


1

Well, you can rely on the policy that in the preamble, one uses \usepackage, whereas in the packages and classes, it's \RequirePackage: \documentclass[a4paper]{article} \def\usedpackages{} \let\xusepackage\usepackage \renewcommand\usepackage[2][]{\edef\usedpackages{\usedpackages#2,}\xusepackage[#1]{#2}} \usepackage[margin=0pt]{geometry} ...


0

OK, managed to do something - but, of course, a more erudite answer will be greatly appreciated. First, here is the usage example: %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \documentclass{article} %%% start scanning \input{_usedpackages.tex} \usepackage{filecontents} % tlmgr install filecontents ...


0

Ok, I got at least a working version - though I cannot say I understand what is going on; so a more erudite answer would still be appreciated. But after some messing about, I got a "two-step" approach with call to \protected@edef to work. Here is the MWE: \documentclass{article} \usepackage{filecontents} % tlmgr install filecontents ...


4

\PassOptionsToPackage{demo}{graphicx} \documentclass[12pt]{beamer} \usepackage{tikz} \usetikzlibrary{calc} \tikzset{credit/.style={ append after command={ let \p1=($(\tikzlastnode.north east)-(\tikzlastnode.north west)$) in node[anchor=north east,align=right,text width=\x1,font=\footnotesize, node contents={Source:~\textit{#1}}, at = ...


5

\PassOptionsToPackage{demo}{graphicx} \documentclass[12pt]{beamer} \newcommand{\credit}[1]{\par\hfill \footnotesize Credit:~\itshape#1} \begin{document} \begin{frame}{demo} \includegraphics[width=\linewidth]{demo} \credit{where credit is due.} % How best to implement this? \end{frame} \end{document}


3

The Tufte classes define an author command in a way, that a thanks is gobbled and just the name is stored (thankslessauthor). If an optional argument to \author was given, this is stored as the plainauthor, if none was given, thanklessauthor and plainauthor are the same. As you can see on the last page of the example, if the thanks is not gobbled, the ...


4

I would recommend you just change the \to arrow and use tikz to draw that: As per your comments you want an arrow without limits but a longer arrow when in \displaystye. That can be achieved with the use of \mathchoice: although I am not sure exactly what this symbol means. Code: \documentclass{article} \usepackage{amsmath} \usepackage{tikz} ...


4

Here is a common solution without any expl3, etoolbox etc. The \and macro can be defined as required. We need only three lines of macros: \def\mylist#1{\mylistA #1\and\and} \def\mylistA#1\and{\ifx\and#1\and\else \and{#1}\expandafter\mylistA\fi} \def\and#1{$\underline{\rm #1}$ } \mylist{Element1 \and Element2} Edit: Egreg's comment here includes question, ...


1

If you are not bound by the idea to limit items by \and you may want to take a look at the packages commado or dowith that I recently discovered when having a similar problem. With the former you could try something along the lines \usepackage{commado} % ... \newcommand{\myList}[2][\underline]{\doWithCSL{#1}{#2}} and call it like ...


0

I met the same problem when I tried to include the output of the Unix cal command inside a LaTeX macro. Enclosing the cal output within the verbatim environment does not work for reasons cited above. My solution is a hack. Create a LaTeX document (calendar-out.tex) containing only the output of cal and inside a verbatim environment. Convert ...



Top 50 recent answers are included