I'm typesetting in LaTeX, and I'd like to display a "variable" (in my case, a reference \ref{blah} to an item number in list) in roman rather than the default arabic. Is there an easy way to do this? Thanks for any pointers!
You can try \def\theenumi{\roman{enumi}} inside an enumerate environment -- this changes both labels and refs, but you'll have to then explicitly undo it (if you want to).
lowercase
\romannumeral 0\ref{blah}\relax
uppercase
\uppercase\expandafter{\romannumeral 0\ref{blah}}
What are the references to? Usually, you would redefine how that particular counter is displayed.
For example, to change how a section number is displayed, you could use the following command:
\renewcommand\thesection{\Roman{section}}
Now, each command that internally uses \thesection will print the section number as a roman numeral.
Similar commands work for chapter, figure etc.
\roman (lowercase r) yield lowercase roman numerals.
For lowercase: {\romannumeral \ref{blah}}
For uppercase: \uppercase\expandafter{\romannumeral \ref{blah}}
A good solution seems to me to declare
\renewcommand{\theenumi}{\roman{enumi}}
\renewcommand{\labelenumi}{(\theenumi)}
in the header and then cite by \eqref{blah} to get your (iii) for the third item. (Note that \eqref requires the amsmath package. Alternatively, write (\ref{blah}).)
Related
I am using TeXnicCenter to edit a LaTeX document.
I now want to remove a certain tag (say, emph{blabla}} which occurs multiple times in my document , but not tag's content (so in this example, I want to remove all emphasization).
What is the easiest way to do so?
May also be using another program easily available on Windows 7.
Edit: In response to regex suggestions, it is important that it can deal with nested tags.
Edit 2: I really want to remove the tag from the text file, not just disable it.
Using a regular expression do something like s/\\emph\{([^\}]*)\}/\1/g. If you are not familiar with regular expressions this says:
s -- replace
/ -- begin match section
\\emph\{ -- match \emph{
( -- begin capture
[^\}]* -- match any characters except (meaning up until) a close brace because:
[] a group of characters
^ means not or "everything except"
\} -- the close brace
and * means 0 or more times
) -- end capture, because this is the first (in this case only) capture, it is number 1
\} -- match end brace
/ -- begin replace section
\1 -- replace with captured section number 1
/ -- end regular expression, begin extra flags
g -- global flag, meaning do this every time the match is found not just the first time
This is with Perl syntax, as that is what I am familiar with. The following perl "one-liners" will accomplish two tasks
perl -pe 's/\\emph\{([^\}]*)\}/\1/g' filename will "test" printing the file to the command line
perl -pi -e 's/\\emph\{([^\}]*)\}/\1/g' filename will change the file in place.
Similar commands may be available in your editor, but if not this will (should) work.
Crowley should have added this as an answer, but I will do that for him, if you replace all \emph{ with { you should be able to do this without disturbing the other content. It will still be in braces, but unless you have done some odd stuff it shouldn't matter.
The regex would be a simple s/\\emph\{/\{/g but the search and replace in your editor will do that one too.
Edit: Sorry, used the wrong brace in the regex, fixed now.
\renewcommand{\emph}[1]{#1}
any reasonably advanced editor should let you do a search/replace using regular expressions, replacing emph{bla} by bla etc.
I have several lemmas in which I specify constants $C_1$, $C_2$, and so forth for later reference. Naturally, this is annoying when I later insert a new constant definition in the middle. What I'd like is a macro that lets me assign labels to constants and handles the numbering for me. I'm thinking something along the lines of
%% Pseudocode
\begin{lemma}
\newconstant{important-bound}
We will show that $f(x) \le \ref{important-bound} g(x)$ for all $x$.
\end{lemma}
Is this possible?
Expanding on rcollyer's suggestions of using a counter:
%counter of current constant number:
\newcounter{constant}
%defines a new constant, but does not typeset anything:
\newcommand{\newconstant}[1]{\refstepcounter{constant}\label{#1}}
%typesets named constant:
\newcommand{\useconstant}[1]{C_{\ref{#1}}}
(This code was edited to allow labels longer than one character)
And here is a code snippet that seems to work:
I want to define two constants:\newconstant{A}\newconstant{B}$\useconstant{A}$ and
$\useconstant{B}$. Then I want to use $\useconstant{A}$ again.
What you're looking for is to create your own counter.
Expanding on Aniko's answer, I used
this layered macro so that it created a shorthand for the label,
\newcounter{constant}
\newcommand{\newconstant}[1]{\refstepcounter{constant}\label{#1}}
\newcommand{\useconstant}[1]{C_{\ref{#1}}}
\newcommand{\defconstant}[1]{ \newconstant{c_#1}\expandafter\newcommand\csname c#1\endcsname{\useconstant{c_#1}} } %
So to use this, you would then do
\defconstant{a}
\defconstant{b}
There exist constant $\ca$ and $\cb$ such that ....
careful not to overwrite existing commands (i'm sure it would warn you anyhow)
I am trying to write programming code in latex using the verbatim environment, but when I write
\begin{verbatim}
char ch = 'x';
\end{verbatim}
then the ' -characters around x are displayed incorrectly (they look "curly"). How can I fix this problem?
Load the upquote package to fix this issue in verbatim mode.
If you want straight quotes in monospaced text mode (e.g., \texttt{...}), or indeed in any other font, then you can use the \textquotesingle command defined in the textcomp package:
\documentclass{article}
\usepackage{upquote,textcomp}
\begin{document}
\newcommand\upquote[1]{\textquotesingle#1\textquotesingle}
\verb|'c'| \texttt{\upquote{h}}
\textsf{\upquote{h}} \upquote{h}
\end{document}
This will work well for fonts in any encoding rather than depending on a specific glyph slot (such as \char13 in the default OT1 encoding).
Adding \usepackage{upquote} to my preamble was sufficient.
Perhaps older versions of LaTeX or upquote required more work.
I have
What is wrong?
New
If you want to get something like this
write
\makeatletter
\let \#sverbatim \#verbatim
\def \#verbatim {\#sverbatim \verbatimplus}
{\catcode`'=13 \gdef \verbatimplus{\catcode`'=13 \chardef '=13 }}
\makeatother
For displaying source code, you might consider using the listings package; it is quite powerful and offers an option to display “straight” quotation marks.
If you're seeing curly single right quotes in a verbatim environment, then the single right quote in your typewriter font is curly, and that's the correct one to use for what you're doing (which I assume is displaying some C code).
\textsf{``} and \textsf{''} come pretty close to straight quotes. No need for using any special packages.
This is what I got from another source, and this works.
Use `` to start the double quotes (this symbol is below ~ symbol on our keyboard)
Use '' to close the double quotes (this symbol is below the " symbol on our keyboard)
So, `` quote double, unquote double''
Same goes for single quotes, `quote single, unquote single'
I'd like to express the following sentence (source_location is also italic, it's not correctly rendered):
Each entry has a list of tuple: < source_location, R/W, trip_counter, occurrence, killed (explained in the later) >
My current workaround for this is:
$ \left\langle
\textit{source\_location}, \textit{R/W}, \textit{trip\_counter},
\textit{occurrence}, \textit{killed} \text{(explained in the later)}
\right\rangle $
I'm using 2-column paper. This < .. > is too long, but no line break because it is a math. How do I automatically (or manually) put line break in such case? It seems that \left\langle and \right\rangle should be in a single math. So, hard to break into multiple maths.
$<$ and $>$ would be an alternative, but I don't like it.
LaTeX does allow inline maths to break over lines by default, but there are a number of restrictions. Specifically, in your case, using \left...\right puts everything inside a non-breakable math group, so the first step is to replace them with either just plain \langle...\rangle or perhaps \bigl\langle...\bigr\rangle.
However, this still isn't enough to permit linebreaking; usually that's still only allowed after relations or operators, not punctuation such as the comma. (I think this is what's going on anyway; I haven't stopped to look this up.) So you want indicate where allowable line breaks may occur by writing \linebreak[1] after each comma.
Depending how often you have to do this, it may be preferable to write a command to wrap your "tuples" into a nice command. In order to write this in your source:
$ \mytuple{ source\_location, R/W, trip\_counter, occurrence,
killed\upshape (explained in the later) } $
here's a definition of \mytuple that takes all of the above into account:
\makeatletter
\newcommand\mytuple[1]{%
\#tempcnta=0
\bigl\langle
\#for\#ii:=#1\do{%
\#insertbreakingcomma
\textit{\#ii}
}%
\bigr\rangle
}
\def\#insertbreakingcomma{%
\ifnum \#tempcnta = 0 \else\,,\ \linebreak[1] \fi
\advance\#tempcnta\#ne
}
\makeatother
Why not define a new command:
\newcommand{\tuple}[5]{$\langle$\textit{#1}, \textit{#2}, \textit{#3}, \textit{#4},
\textit{#5} (explained in the latter)$\rangle$}
Then use \tuple{sourcelocation}{R/W}{tripcounter}{occurrence}{killed}
There seems to be a package that addresses that problem, called breqn. You can try this and let us know (I haven't used that).
I'd use the align* environment from AMSmath. Furthermore you could just add "\" to break the lines? Should work in math environments, too. Alternatively you could separate the equations.
Use \linebreak inside the math expression wherever you want a new line even between 2 brackets. This will enforce the line to be broken.
vi treats dash - and space as word separators for commands such as dw and cw.
Is there a way to add underscore _ as well?
I quite often want to change part of a variable name containing underscores, such as changing src_branch to dest_branch. I end up counting characters and using s (like 3sdest), but it would be much easier to use cw (like cwdest).
Is there a way to add underscore _ as well?
:set iskeyword-=_
What is, and is not a member character to keywords depends on the language. For help on iskeyword use :help iskeyword.
In case you're using vim, you can change that by setting the iskeyword option (:he iskeyword). If that is not an option, you can always use ct_ instead of counting.
One other good option in such cases is to use camelcasemotion plugin.
It adds new motions ,b, ,e, and ,w, which work analogously with b, e, and w, except that they recognize CamelCase and snake_case words. With it you can use
c,edest
and this will replace "src_branch" with "dest_branch" if your cursor was on first character of "src_branch".
You could type cf_dest_ and save the counting part.
Edit: or as suggested: ct_ changes text until right before the underline character. (I'm using the f motion more, so it came more naturally to me)
Or you could redefine 'iskeyword' (:help iskeyword for details).
I was just looking at this myself and added this to my .vimrc:
set iskeyword=!-~,^*,^45,^124,^34,192-255,^_
My .vimrc had issues with ^| and ^", which was part of the default iskeyword for my setup, so I changed to their ascii values and it works fine. My main modification was to add "^_" to the end of the default setting to keep vim from seeing underscore as being part of a word.
To delete to the next underscore enter "df_"
To change to the next underscore enter "cf_"
NOTE: don't include the double quotes.