How do I indicate an en-dash while in math mode using LaTeX? - latex

There are four kinds of 'dashes' in LaTeX: hyphen, en-dash(--), em-dash(---) and minus $-$. They are used for, respectively, hyphenation and joining words, indicating a range, punctuation, and a mathematical symbol. My question is: how do I indicate an en-dash (range) in math mode? (as in $S=1 to 2$)? Do I have to drop out of math mode in the middle of the 'equation' ($S=1$--$2$)? Or is there a symbol I can use and stay in math mode? I tried $S=1\--2$ but this gives me a minus, not a en-dash, and $S=1--2$ gives two minuses. My guess is I am going to have to drop out of math mode but maybe there is a way to do it without that.

The simplest way is to use $S=1\mbox{--}2$. If you already have \usepackage{amsmath} in your document's preamble, however, you're better off using \text: $S=1\text{--}2$ because \text will adjust the size of the font when used in super- and subscripts: $S_{1\text{--}2}=0$.
An en dash used in math may easily be confused with a minus sign. You may want to look at other techniques for indicating a range such as ellipses (\ldots for dots on the baseline [used between commas], or \cdots for centered dots [used between centered operators such as plus signs]) or using the bracket notation. Some examples:
$S = \{1, 2, \ldots, n\}$ indicates an element in the set containing integers between 1 and $n$.
$S = [0, 1]$ indicates a real number between 0 and 1 (inclusive).

You can use \textrm which does not depend on \usepackage{amsmath}.
Some examples:
$S=1\textrm{--}2$
$S_{1\textrm{--}2}=0$ % correctly changes the font size for subscript
$S_{1\textrm{2}2}=0$ % does not change the font size :(
Or maybe use \textnormal instead of \textrm.
See also LaTeX: use \textnormal instead of \textrm (or \textsf) in math.

Well, you could use $1\mbox{--}2$, but I'd look at the list of math symbols in the symbol list. Hmm. I don't find one.

Use the command \leftrightline in the package MnSymbol. I don't know if it's the length needed for your purposes, but hopefully it will do the trick.

Related

Font scaling, variables, calculations in LaTeX

I'm currently writing my CV and I'm running out of space. I wish to change the font in the whole CV template, but I want to do it proportionally. For example, some headings are 12pt, subheadings are 11pt. I want to be able to change them to 0.9 * 12 pt, 0.9 * 11 pt, aka to scale them accordingly. I want to change
\fontsize{12pt}{1em}
to
\fontsize{(0.9 * 12)pt}{1em}
, where \fontsize is a command from anyfontsize package.
But I end up with weird results and lots of logs/mistakes. Is there a way to ensure that '*' will produce a number, like in "regular" programming languages?
Other things I've tried include:
\newcommand{\myfont}[2]{\fontsize{0.9*#1pt}{0.9*#2}em}
\myfont{12}{1}
But it doesn't work the way I expect it to. I also tried adding brackets () and making a new command \newcommand{\mymultiply}[2]{#1*#2}
Is there an elegant and neat way to do this? Is there a "regular" way in LaTeX of doing actual calculations, or should I avoid this approach? Thanks in advance!
3 possible approaches:
I would avoid using hard coded font sizes altogether. If you instead us font commands like \smaller or \larger you can simply change the overall size with documentclass options like 10pt or 12pt and all the fonts in the document will scale, including sections etc.
if you store your base fontsize in a length, you could use \dimexpr to make the calculations
if for whatever reason you don't want to create a new length, you use an expl3 command to do the calculations
\documentclass[
%10pt
12pt
]{article}
\usepackage{anyfontsize}
\ExplSyntaxOn
\cs_new_eq:NN \fpeval \fp_eval:n
\ExplSyntaxOff
\begin{document}
\section{section}
section
\newlength{\foo}
\setlength{\foo}{12pt}
\fontsize{\dimexpr.9\foo\relax}{\dimexpr1.08\foo \relax}\selectfont
test
\fontsize{\dimexpr\fpeval{.9*12}pt\relax}{\dimexpr\fpeval{.9*1.2*12}pt\relax}\selectfont
test
\end{document}

How to make all numbers and letter take up the same amount of space in latex?

I'm trying to show step by step how to sort an array. But since the numbers and letters take up different amounts of space, the columns get staggered. I'm very new to latex and am not sure if there's an easy fix for this.
If that's not possible, is there some kind of grid system I can use to keep them in straight lines? (without showing the grid).
You can place each of the elements in a box that are of similar width and height. This will ensure that each take up the same amount of space. It's possible using eqparbox's \eqmakebox[<tag>][<align>]{<stuff>}. All \eqmakeboxes with the same <tag> are put in a box of maximum width of <stuff>. You can adjust the <align>ment of every element, if needed (centred, left-aligned or right-aligned).
\documentclass{amsart}
\usepackage{eqparbox}
\newcommand{\swl}[2][nmbr]{\eqmakebox[#1]{\strut #2}}
\begin{document}
\begin{tabular}{c}
\swl{a}\swl{b}\swl{m}\swl{0} \\
\swl{i}\swl{i}\swl{1}\swl{n}
\end{tabular}
\end{document}
The above code provides a wrapper \swl[<tag>]{<stuff>} that provides a similar-width letter macro. If you want a blank space, you can use \swl{~}.
eqparbox uses TeX's \label-\ref system to store the widths and therefore requires at least two compilations for any change (increase in width) in elements under the same <tag>.

Why the display of Unicode characters for superscripted digits are not at the same height?

Why the display of Unicodes for superscripts of digits are not at the same height? This is specially noticeable if you make two digit numbers out of the superscript digits. Some of them look fine but the rest look out of the place with respect to each other. Am I missing something? Or is this how it is?
Like jrturton mentions, ¹, ² and ³ were from a legacy character set (Latin 1) and therefore included in a different place. This also means that lots of fonts don't have support for more superscript numbers, as many only strive for Latin, Greek and Cyrillic with a few punctuation symbols thrown in. So the remaining ones are taken from a different font over which you as an author have little to no control.
As an example:
Those are the superscript numerals from 1 to 9 and 0. The run of text was formatted in Arial in Word. You see what happened to the rest of them. Contrary to what jrturton believes, there is no reshaping of existing glyphs involved. This is just font substitution.
The out of place ones (1,2 and 3) were added before the rest (see wikipedia: http://en.wikipedia.org/wiki/Unicode_superscripts_and_subscripts), and are from a different unicode block. That doesn't explain why they look different but it may be that those ones are actual characters in most fonts, and the remaining ones are just adjusted versions of the standard glyphs.
This appears to be how it is and you are right, it looks terrible when you are trying to make multi digit superscript numbers. I don't know if it applies to all fonts but it is very noticeable on the iOS system font.
If anyone has a way to make this work, I will put a bounty up on this question.
UPDATE
I knocked up a little program to cycle through all fonts on the phone and display the superscript numerals from 0 to 9. The following fonts had a consistent appearance across all digits:
Zapfino
Courier-Bold
AmericanTypewriter (also -Bold)
HiraKakuProN-W6 (also -W3)
Noteworthy-Bold (also -Light)

Vertical placement of math symbol in LaTeX

I'm using the symbol \otimes as a unary operator and it's vertical alignment doesn't seem right to me. It wants to sit a bit below the baseline. For example, if I define \newcommand{\myop}{\ensuremath \otimes}, then $\myop I$ becomes
and $F_{\myop I}$ becomes
I tried using \raisebox to fix this, e.g.,
\newcommand{\myop}{\ensuremath \raisebox{1pt}{$\otimes$}}
This fixes $\myop I$:
But \raisebox doesn't seem to be sensitive to subscripts. The operator stays the same size while everything around it shrinks:
The problem, I think, is that \raisebox creates its own LR box, which doesn't inherit the settings in the surrounding math environment. Is there a version of \raisebox that "respects math"?
Try \mathchoice (or \mathpalette):
\newcommand{\myop}{%
\mathchoice{\raisebox{1pt}{$\displaystyle\otimes$}}
{\raisebox{1pt}{$\otimes$}}
{\raisebox{0.5pt}{$\scriptstyle\otimes$}}
{\raisebox{0.2pt}{$\scriptscriptstyle\otimes$}}}
The amsopn documentation says:
... the vertical spacing may not be optimal in script and scriptscript
sizes. Unfortunately TeX provides no easy way to do math mode vertical spacing
that varies with current math style like mu units.
$F_{\raisebox{1pt}{\scriptsize$\otimes$} I}$

Manipulating line spacing in LaTeX

I have a block of text in a quotation. Some of that text will be in a very small font (\scriptsize) and some much bigger (\Large). My problem is that the letters in the big font push right up against the letters in the line above. This effect is unacceptably distracting to the reader. (Trust me; for my use, it is.)
My question, then: how do I insert space to push apart the lines so that the large text does not scrape against the text above it?
You can specify \vspace in postscript points. This will give you very fine-grained control.
or...
you can use the setspace package: \usepackage{setspace} then use the commands:
\singlespacing
\onehalfspacing
\doublespacing
or...
you can use \linespacing{factor}: Use
\linespread{1.3} for "one and a half" line spacing, and
\linespread{1.6} for "double" line spacing.
Normally the lines are not spread, so the default line spread factor is 1.
There are myriad methods, but in paper writing, I often use a \vspace{0.75cm} after the separating newline (I'm metric, so pick a unit you like).

Resources