How to insert special characters when writing to a text file with LaTex - latex

This is my first post here. I can usually find what I'm looking for using questions other people have asked, but this time I'm stumped. Please can anyone help?
I'm trying to get Latex to generate a text file every time it is compiled (this bit I can do). I need the text file to have the following format
text text
I have found out how to output a text file from LaTex, but I can't get it to insert a tab, only a space. A post here on StackOverflow shows how to include the backslash character in the text output using the following code:
\makeatletter
\immediate\write\outputfile{text \#backslashchar text}
\makeatother
I'm sure that something similar must work for inserting a tab, but I can't find a solution.
If anyone here knows how to do this I would be very, very grateful.
Many thanks!

There is no counterpart to the concept of a tab in (La)TeX, except when you are aligning the columns in a table. If what you meant by a tab is indentation at the beginning of a paragraph, that is considered a matter of design. Namely, the \parindent parameter specifies the distance that each paragraph should be indented. There is no 'tab' character that occupies the initial position of each paragraph.
However, you can forcefully insert a space in an arbitrary position. For example, use \hspace{distance}, where distance can be something like '3em' (3 times the width of m) or '1cm'.

Related

How to label boxed text in markdown?

My question in short is: How can you create a boxed text with a label that can be referenced?
Background: I am generating LaTeX output from a Markdown document to be included in a larger LaTeX document. I would like to describe the steps of an algorithm as boxed text with a label that can be referenced. I know how to create a labeled figure and how to create boxed text, but I haven't been able to figure out how to combine the two, i.e. how to label the boxed text as if it was a figure, or how to include the text in a figure (other than converting it to an image, which I'd like to avoid).
An initial "solution": Just putting a the box and an empty figure next to each other (see below) kind of works, except that nothing ensures that the figure label won't float away from the box as I work on the document, since figures are floating objects while text boxes are part of the text, and the two are handled differently by LaTeX. Moreover, you may need to use LaTeX vertical space commands to make it look reasonably good, but it is hard to get it perfect. Is there a simple solution? Thanks!
P.S. I know that I could just switch to LaTeX and figure out a solution there, but here I am looking for a solution in Markdown, possibly making use of some embedded LaTeX commands.
You can see the algorithm in Figure \ref{methods:estimating}.
\fbox{\parbox{5in}{
1. Initialize $b_r=0$ for $r=1..R$ \\
2. For each item $i, i=1..U$, calculate ... \\
3. Re-estimate ... \\
4. Proceed to Step 2 until it converges.
}}
![Estimating ... \label{methods:estimating}]()
It is rendered like this:
You can use one of the packages for writing algorithms. See https://www.sharelatex.com/learn/algorithms.

Character spacing in LaTeX with lstlisting package

I'm trying to get my code snippets to look as good as possible and so far I'm having troubles with the character spacing. Here is an example of the output:
alt text http://grab.by/grabs/2bb230de7c088d007733f52b95a40363.png
While the text in small is perfect, all the keywords that are in capital letters look terrible. Here are the settings I use
\lstset{basicstyle=\footnotesize, basewidth=0.5em}
If I increase the basewidth, the capital letters look good, but I can't get any decent sized line of code in one line. The following example does not fit in a page and I already put two line breaks in:
alt text http://grab.by/grabs/97ec29aa5a6811ce28bcd30bd389b52f.png
Does anyone have a clue how I can get this to work? Using \ttfamily does the trick, however, I'd prefer keeping the font.
Thanks.
If you prioritize looking nice, then using flexible colums is preferable:
\lstset{basicstyle=\footnotesize, columns=fullflexible}
You "obviously" need to scale the capital letters down horizontally. I do not know of a way to do this without actually editing the font itself.
However, you could put the entire listing into a \scalebox resp. \resizebox (from the graphicx package).
On a side note, the font you are using seems a bit strange, though, since the distance between small letters is significantly bigger than that between capital letters.

What is a vertical tab?

What was the original historical use of the vertical tab character (\v in the C language, ASCII 11)?
Did it ever have a key on a keyboard? How did someone generate it?
Is there any language or system still in use today where the vertical tab character does something interesting and useful?
Vertical tab was used to speed up printer vertical movement. Some printers used special tab belts with various tab spots. This helped align content on forms. VT to header space, fill in header, VT to body area, fill in lines, VT to form footer. Generally it was coded in the program as a character constant. From the keyboard, it would be CTRL-K.
I don't believe anyone would have a reason to use it any more. Most forms are generated in a printer control language like postscript.
#Talvi Wilson noted it used in python '\v'.
print("hello\vworld")
Output:
hello
world
The above output appears to result in the default vertical size being one line. I have tested with perl "\013" and the same output occurs. This could be used to do line feed without a carriage return on devices with convert linefeed to carriage-return + linefeed.
Microsoft Word uses VT as a line separator in order to distinguish it from the normal new line function, which is used as a paragraph separator.
In the medical industry, VT is used as the start of frame character in the MLLP/LLP/HLLP protocols that are used to frame HL-7 data, which has been a standard for medical exchange since the late 80s and is still in wide use.
It was used during the typewriter era to move down a page to the next vertical stop, typically spaced 6 lines apart (much the same way horizontal tabs move along a line by 8 characters).
In modern day settings, the vt is of very little, if any, significance.
The ASCII vertical tab (\x0B)is still used in some databases and file formats as a new line WITHIN a field. For example:
In the .mer file format to allow new lines within a data field,
FileMaker databases can use vertical tabs as a linefeed (see https://support.microsoft.com/en-gb/kb/59096).
I have found that the VT char is used in pptx text boxes at the end of each line shown in the box in oder to adjust the text to the size of the box.
It seems to be automatically generated by powerpoint (not introduced by the user) in order to move the text to the next line and fix the complete text block to the text box. In the example below, in the position of §:
"This is a text §
inside a text box"
A vertical tab was the opposite of a line feed i.e. it went upwards by one line. It had nothing to do with tab positions. If you want to prove this, try it on an RS232 terminal.
similar to R0byn's experience, i was experimenting with a Powerpoint slide presentation and dumped out the main body of text on the slide, finding that all the places where one would typically find carriage return (ASCII 13/0x0d/^M) or line feed/new line (ASCII 10/0x0a/^J) characters, it uses vertical tab (ASCII 11/0x0b/^K) instead, presumably for the exact reason that dan04 described above for Word: to serve as a "newline" while staying within the same paragraph. good question though as i totally thought this character would be as useless as a teletype terminal today.
I believe it's still being used, not sure exactly. There might be even a key combination of it.
As English is written Left to Right, Arabic Right to Left, there are languages in world that are also written top to bottom. In that case a vertical tab might be useful same as the horizontal tab is used for English text.
I tried searching, but couldn't find anything useful yet.

Latex: How to cells in tables which wrap, but can still be copied as a single line

I am trying to create a table over inputs to a tool which requires the entire input to be on a single line.
My question is similar to Latex: How to code tables with multi-line cells in that I want the long lines to wrap.
The problem is that when I copy the text from the PDF using Acrobat Reader it does not copy the lines as a single.
If I copy the first multi-line cell in the example I get
Betty Botter Bought a Bit of Butter
but the Butter's Bitter
My goal is to get it as a single line.
Betty Botter Bought a Bit of Butter but the Butter's Bitter
Is there a way to make it wrap the text while copying the wrapped line as a single line?
I'm trying to figure out what your issue is. Whether your editor and/or Acrobat coies the text as a single line is an issue unrelated to LaTeX. That is, LaTeX doesn't care whether the text is in a single line or whether it's broken into multiple lines, the output is the same, at least when using the column width specification in the answer to the question you linked.
You might get a better response to your question if you clarify why you don't want the text to be copied in multiple lines. Is it making some difference in the output (e.g., wrapping at an incorrect spot)? Some sample code that shows the problem would be helpful.

Is there a way to get LaTeX to place figures in the same page as a reference to that figure?

I am using LaTeX and the figure environment.
I am well familiar with the parameters to that environment: [htbp], and I am also generally familiar with the strategies that LaTeX takes, by default, to decide where to put each figure. For example, by placing figures at the top or bottom of the page.
What I am wondering is whether there is a package, macro, or some commands that I can give so that if I have a single-column document and I mostly have a single in-text reference to a figure, that the figure would be more likely to be placed in the same page of the reference?
For example, imagine that I have a long paragraph which in the middle has a \ref{FIG:X}. When rendered, some of the paragraph appears before the page break, and some appears after the page break. I can also place the figure command somewhere before and after the whole paragraph. Is there a way to get it to actually be placed in the same page as the actual reference?
I don't want to sound too negative, but there are occasions when what you want is almost impossible without a lot of "artificial" tuning of page breaks.
If the callout falls naturally near the bottom of a page, and the figure falls on the following page, moving the figure back one page will probably displace the callout forward.
I would recommend (as far as possible, and depending on the exact size of the figures):
Place the figures with [t] (or [h] if you must)
Place the figures as near as possible to the "right" place (differs for [t] and [h])
Include the figures from separate files with \input, which will make them much easier to move around when you're doing the final tuning
In my experience, this is a big eater-up of non-available time (:-)
In reply to Jon's comment, I think this is an inherently difficult problem, because the LaTeX guys are no slouches. You may like to read Frank Mittelbach's paper.
Yes, include float package into the top of your document and H (capital H) as a figure specifier:
\usepackage{float}
\begin{figure}[H]
.
.
.
\end{figure}
You can always add the "!" into your float-options. This way, latex tries really hard to place the figure where you want it (I mostly use [h!tb]), stretching the normal rules of type-setting.
I have found another solution:
Use the float-package. This way you can place the figures where you want them to be.
I solve this problem by always using the [h] option on floats (such as figures) so that they (mostly) go where I place them. Then when I look at the final draft, I adjust the location of the float by moving it in the LaTeX source. Usually that means moving it around the paragraph where it is referenced. Sometimes I need to add a page break at an appropriate spot.
I've found that the default placement of floats is reasonable in LaTeX, but manual adjustments are almost always needed to get things like this just right. (And sometimes it isn't possible for everything to be perfect when there are lots of floats and footnotes.)
The manual for the memoir class has some good information about how LaTeX places floats and some advice for manipulating the algorithm.
If you want force this behaviour on all of your figures try
...
\usepackage{float}
\floatplacement{figure}{H}
...
Maybe this will help you?
\begin{center}
\includegraphics[scale=0.5]{picture_name}
\end{center}
I think is better to use the graphics command when your figures run away.
I have some useful comments. Because I had similar problem with location of figures.
I used package "wrapfig" that allows to make figures wrapped by text.
Something like
...
\usepackage{wrapfig}
\usepackage{graphicx}
...
\begin{wrapfigure}{r}{53pt}
\includegraphics[width=53pt]{cone.pdf}
\end{wrapfigure}
In options {r} means to put figure from right side. {l} can be use for left side.
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{4}
\renewcommand{\topfraction}{0.85}
\renewcommand{\bottomfraction}{0.85}
\renewcommand{\textfraction}{0.15}
\renewcommand{\floatpagefraction}{0.7}
http://robjhyndman.com/researchtips/latex-floats/
One way I found that helps with this is to use \include{file_with_tex_figure_commands}
(not input)

Resources