How to prevent LaTeX from hyphenating words containing a dash? - latex

I would like to globally prevent LaTeX from hyphenating 'Objective-C'. I am aware of the \hyphenation command, but I don't see how I can make use of it. If I pass 'Objective-C' to this command, the dash will be treated as a hint to hyphenate the word there.
One solution I found is wrapping Objective-C into an mbox each time I use it. However, the document I am writing contains this name a lot, and wrapping it into an mbox each time is ugly (as is defining a command and using this over and over again in the source code).

Why is defining a new command ugly? It's how \LaTeX\ defines itself.
\def\ObjectiveC{\mbox{Objective-C}}

Use \nobreakdash. That's what LyX produces when I insert a nonbreakingdash and convert it to tex.

As suggested here, you could define a command like this:
\newcommand\dash{\nobreakdash-\hspace{0pt}}
and use it like this
Consider the $n$\dash dimensional manifold ...
Also, you could use the babel package and use "~ as a protected hyphen. I'm not sure if using babel is advisable when writing in english, though.

Related

Change format of inline code evaluation in org-mode's LaTeX-export

I have a code block in an org document
#+NAME: result_whatever
#+BEGIN_SRC python :session data :results value :exports none
return(8.1 - 5)
#+END_SRC
which I evaluate inline:
Now, does this work? Let's see: call_result_whatever(). I'd be surprised ...
When exporting to LaTeX, this generates the following:
Now, does this work? Let's see: \texttt{3.1}. I'd be surprised \ldots{}
However, I don't want the results to be displayed in monospace. I want it to be formatted in "normal" upright font, without any special markup.
How can I achieve this?
You should be able to get it work using the optional header arguments which can be added to call_function().
I don't have LaTeX installed on this system so can't fully test the outputs to ensure they come out exactly as desired, I'm using the plain text output to compare instead. However you can use the following syntax as part of your call to modify the results.
Now, does this work? Let's see call_results_whatever()[:results raw].
I'd be surprised ...
Without the [:results raw] the output to Plain Text (Ascii buffer) is Let's see `3.0999999999999996'.. With the added results it becomes Let's see 3.0999999999999996.
For full details of the available results keywords as well as other optional header arguments for the inline blocks please see Evaluation Code Blocks and Results arguments.
this is 5 years later. apparently in org-mode 8.2 or so, a new variable was introduced (documenting in "Evaluating Code Blocks" in the org-mode manual, but this from etc/ORG-NEWS in the source tree):
*** New option: org-babel-inline-result-wrap
If you set this to the following
: (setq org-babel-inline-result-wrap "$%s$")
then inline code snippets will be wrapped into the formatting string.
so, to eliminate \texttt{}
(setq org-babel-inline-result-wrap "%s")
The problem of this type can be solved in two ways:
1: Easy does it:
A plain query-replace on the exported buffer.
Once you're in the LaTeX buffer,
beginning-of-buffer or M-<
query-replace or M-%
enter \texttt as the string that you want to replace
enter nothing as the replacement
continue to replace each match interactively
with y/n or just replace everything with !
2: But I wanna!
The second way is to nag the org-mode mailing list into
implementing a switch or an option for your specific case.
While it's necessary sometimes, it also produces a system
with thousands of switches, which can become unwieldy.
You can try, but I don't recommend.

LaTeX: Redefining the citation macro temporarily

I'm new to latex, but it seems you can temporarily redefine some commands? The problem I have is that normally the citation is (SMITH, 2000). But at times, I'd like to have Smith (2000) instead. Anyway I can temporarily redefine it, then use the standard version again after that "block" of code?
Enclose the local definition in braces ({}).
\newcommand\foo{FOO!}
\foo
{\renewcommand\foo{BAR?}\foo\foo}
\foo
This will generate something like:
FOO!BAR?BAR? FOO!
This can be done inside macro definitions, too - just make sure you add the extra braces:
\newcommand\newfoo{{\renewcommand\foo{BAR?}\foo}}
Hope this helps.
You should already have \citep and \citet commands that should do what you want, there's no reason to redefine the macros yourself.

Automatically QED in LaTeX's newtheorem command

As the title says I need to define a QED symbol automatically (preferable a colorbox) at the end of my custom newtheorem.
Any suggestions would be appreciated.
Advice: don't do it. The placing of the QED symbol depends in a non-straightforward way on the contents of your text in your environment. For instance, Andrea's code will fail if your theorem ends with display math. You will probably need to place it by hand sometimes, and you are less likely to overlook things if you always do this.
Much better would be to have an environment that complains if the QED symbol has not been placed. You can do this by defining a qedused flag, say by \newififqedused, that is unset when you enter the environment (define a wrapper using \newenvironment as Andrea said), set in a wrapper around the QED symbol, and tested when you exit the environment. If the flag is still unset on exit, issue a \PackageWarning or \PackageError.
If you really want to try to get a qed environment that tries hard to do the right thing, regardless of what is in the environment, you'll need to look into the contents of \lastbox to try to determine where the QED symbol should go. If it is an hbox, you are fine, just place the QED as per Andreas' solution. If it is an mbox, then I think making an hbox containing this mbox followed by the QED symbol should work - I'm not sure, I don't usually mess about with the typesetting of maths.
If it is a vbox, you need to look inside the structure of the vbox to find where it should go, which sounds hard - I can't think how to do that in pure Tex. In Luatex, I think that Hans Hagen's trick in The LuaTEX way: \framed might be adapted for this.
I'm not sure what you mean. If you use the package amsthm you have the command \qed to put a QED wherever you want.
You can customize the \qed by changing the command \qedsymbol. So you would do something like
\usepackage{amsthm}
\renewcommand{\qedsymbol}{$\heartsuit$}
\newtheorem{thm}{Theorem}
\newenvironment{\mythm}{\begin{\thm}}{\qed \end{thm}}
...
\begin{mythm}
blah
\end{mythm}
This if you want the QED symbol to be the same that appears in proofs. If not you can do simply
\newtheorem{thm}{Theorem}
\newenvironment{\mythm}{\begin{\thm}}{\hfill $\heartsuit$ \end{thm}}
...
\begin{mythm}
blah
\end{mythm}
Of course you can change \heartsuit with whatever you want.
An alternative is to use the ntheorem package with the options thmarks. that is \usepackage[thmarks]{ntheorem}.
You can then play with the settings to get what you want exactly...

Special names in Latex

In my english thesis latex file, how to mention the following non English words: François, École Fédérale?
Thanks and regards!
The traditional way is to use the accent-adding macros:
Fran\c{c}ois
\'Ecole F\'ed\'erale
(You can also write Fran\c{}cois or Fran\c cois; the \c macro uses no parameter; the braces or space are just a trick to allow LaTeX to see the proper macro name.)
Otherwise, try this:
\usepackage[utf8]{inputenc}
and type the accents directly, with UTF-8 encoding.
There are a host of more-or-less subtle issues with fonts and hyphenation.
If you don't go the UTF8 inputenc route, and yet find yourself writing a lot of these names, I'd suggest defining macros for them. At the simplest, you can say \newcommand\Francois{Fran\c cois} but then you need to be sure to use it as such: \Francois{} so that any spaces afterwards don't get gobbled.
On the other hand, the following technique works pretty well too (though I can't take credit for inventing it - I saw it originally in a short talk at BachoTeX 2009 by Philip Taylor):
\makeatletter
\let\latex#less<
\catcode`<13
\def<{\ifmmode\latex#less\else\expandafter\find#name\fi}
\def\find#name#1>{\#nameuse{name.#1}}
\def\DefineName#1#2{\#namedef{name.#1}{#2}}
\makeatother
Now you can define special names using, e.g.
\DefineName{Francois}{Fran\c cois}
\DefineName{Ecole Federale}{\'Ecole F\'ed\'erale}
and later on you can use them in text with
I ran into <Francois> at the <Ecole Federale> the other day.
You can make your tags (the plain ASCII versions) be whatever you want - they don't have to actually be related to the properly accented names.
EDIT: in response to the issue that misspelled names don't produce errors, you can change the definition of \find#name to
\def\find#name#1>{\ifcsname name.#1\endcsname
\#nameuse{name.#1}%
\else
\#latex#warning{Undefined name #1}%
\fi}
Note that \#latex#warning{...} can be changed to \#latex#error{...}\#eha and it will complain more forcefully. Or if you want to pretend to be (or actually be) a package you can use \Package(Warning|Error){<package name>} in place of \#latex#(warning|error) and it won't pretend to be a built-in LaTeX error anymore.

Annotated Table of Contents in LaTeX

I'd like to use LaTeX's \tableofcontents command (or some equivalent) to automatically generate a table of contents, but I'd also like to add a sentence or two to each line in the table of contents that describes what the referenced section is about. How can I do this?
The tocloft package and its \cftchapterprecistoc command solved my problem.
Try
\addcontentsline{toc}{section}{sample text}
Follwoing Oliver and simon's advice:
You could redefine the sectioning commands to take a second (possibly optional) argument, and use that to build your argument to \addtocontentsline, and then involk the cooresponding section* command.
I expect you can brute force and ignorance something using addcontentsline.
eg:
\addcontentsline{toc}{section}{text}
however, this will conflict with automagically generated lines if you don't use the starred versions of sections it refers to.
Anything more clean will require messing about with the relevant macros....unless I'm missing something.
I would change the {section} part to {subsection}.
\addcontentsline{toc}{subsection}{sample text}

Resources