I have some .rst files and I convert them to .tex file using standard sphinx converter.
In some .rst I have tables with special width like:
.. list-table::
:widths: 50 50
The resulting .tex always contains tables like:
\begin{tabulary}{\textwidth}{|L|L|}
So, the column width is lost.
How can I preserve column width when converting rst to latex?
I used comma separator too,
.. list-table::
:widths: 50 , 50
:header-rows: 1
* - SETTING
- DESCRIPTION
* - Enable
- Enables or disables internal tracing.
* - Verbose
- Enables or disables extended internal tracing.
but it doesn't work.. maybe I used a bad converter? What converter do you recommend?
actually the command
.. tabularcolumns:: |p{4.5cm}|p{8.5cm}|
is needed just before .. list-table::
https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-tabularcolumns
try:
:widths: 50, 50
with a comma separator.
The output also depends on how your table is written in rst.
I assumed that you were using the standard rst table syntax, not making tables from bulleted lists (as is possible). For more help, try http://docutils.sourceforge.net/docs/ref/rst/directives.html#tables
Also, if the 50, 50 is the column width, your latex code should look like this:
\begin{tabulary}{ 1\textwidth}{ | p{0.5} | p{0.5} | }
and:
\begin{tabulary}{total width of table}{| column width| column width|}
The docutils rst2latex writer has some issues with tables: http://docutils.sourceforge.net/docs/dev/todo.html#tables , so maybe your problem is related to that? I think the Sphinx writer is based on rst2latex and might thus have the same issues.
I can confirm that this:
.. list-table::
:widths: 10 40 50
* - Module
- Link
- Description
Works with rst2latex
\setlength{\DUtablewidth}{\linewidth}
\begin{longtable*}[c]{|p{0.104\DUtablewidth}|p{0.375\DUtablewidth}|p{0.465\DUtablewidth}|}
\hline
Module
&
Link
&
Description
\\
\hline
But with sphinx, I get what the OP put. So not an rst2latex issue I would gather.
The "Auto" width stuff the docs talk about is also not very functional for me, links tend to bleed over.
Since I have a huge documentation, I tried to fix the latex generation. Also, I consider Latex notation in rst files a disadvantage, because it's inconsistent and requires editors to partly learn a touchy markup language.
I replaced LaTeXTranslator.depart_table with my own version. I copied the original depart_table and added this code (shortened):
def my_depart_table (self, node):
totalColwidth = 0
givenColwidth = []
hasColwidth = False
for tgroup in node:
for tableColspec in tgroup:
try:
if tableColspec.has_key('colwidth'):
totalColwidth += tableColspec['colwidth']
givenColwidth.append(tableColspec['colwidth'])
hasColwidth = True
except:
print "colspec missing. \n"
# original code
if hasColwidth:
colspec = ""
for thisColwidth in givenColwidth:
colspec += ('>{\RaggedRight}p{%.3f\\linewidth}' % (0.95 * thisColwidth / totalColwidth))
#print "using widths: %.3f %s %s" % ((0.95 * thisColwidth / totalColwidth), thisColwidth, totalColwidth)
self.body.append('{' + colspec + '}\n')
# more original code
LaTeXTranslator.depart_table = my_depart_table
Im neither fluent in Python nor Sphinx, so use at own risk. I hope you get the idea or can even give advice.
If you use Python < 3.0 and want to remove the factor 0.95 completely, remember to either cast one of the integers to float or import division from __ future __.
Related
I understand that Julia has a complete set of low level tools for interfacing with binary files on one hand and some powerfull utilities such as readdlm to load text files containing rectangular data into Array structures on the other hand.
What I cannot discover in the standard library docs, however, is how to easily get input from less structured text files. In particular, what would be the Julia equivalent of the c++ idiom
some_input_stream >> a_variable_int_perhaps;
Given this is such a common usage scenario I am surprised something like this does not feature prominently in the standard library...
You can use readuntil http://docs.julialang.org/en/latest/stdlib/io-network/#Base.readuntil
shell> cat test.txt
1 2 3 4
julia> i,j = open("test.txt") do f
parse(Int, readuntil(f," ")), parse(Int, readuntil(f," "))
end
(1,2)
EDIT: To address comments
To get the last integer in an irregularly formatted ascii file you could use split if you know the character preceding the integer (I've use a blank space here)
shell> cat test.txt
1.0, two five:$#!() + 4
last line 3
julia> i = open("test.txt") do f
parse(Int, split(readline(f), " ")[end])
end
4
As far as code length is concerned, the above examples are completely self contained and the file is opened and closed in an exception safe manner (i.e. wrapped in a try-finally block). To do the same in C++ would be quite verbose.
I've been using Doxygen successfully to generate PDF documentation for a sizable Fortran 90 project since v1.6. After a recent upgrade to Doxygen 1.8, pdflatex is choking with an error I can't understand. From refman.log:
.
.
.
<use classfate__source_a022bf629bdc1d3059ebd5fb86d13b4f4_icgraph.pdf>
Package pdftex.def Info: classfate__source_a022bf629bdc1d3059ebd5fb86d13b4f4_ic
graph.pdf used on input line 607.
(pdftex.def) Requested size: 350.0pt x 65.42921pt.
)
(./classm__aerosol.tex
! Undefined control sequence.
<recently read> \LT#LL#FM#cr
l.25 ...1833ffa6f2fae54ededb}{ia\-\_\-nsize}), \\*
? ?
Type <return> to proceed, S to scroll future error messages,
R to run without stopping, Q to run quietly,
I to insert something, E to edit your file,
1 or ... or 9 to ignore the next 1 to 9 tokens of input,
H for help, X to quit.
Looking at the first 25 lines of classm__aerosol.tex, nothing obviously matches the error message:
\hypertarget{classm__aerosol}{\section{m\-\_\-aerosol Module Reference}
\label{classm__aerosol}\index{m\-\_\-aerosol#{m\-\_\-aerosol}}
}
Contains general aerosol-\/related constants and routines.
\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item
subroutine \hyperlink{classm__aerosol_aa06c1f39c6bd34f22be92d21535f0320}{aerdis} (I\-A\-E\-R\-O, M\-A\-E\-R\-O, V\-O\-L, A\-R\-E\-A, M\-U, T\-G\-A\-S, R\-H\-O, A\-G\-A\-M\-M\-A, X\-L\-A\-E\-R, D\-M\-E\-A\-N, N\-A\-E\-R, X\-N\-D\-A\-E\-R, L\-S\-D\-A\-E\-R)
\begin{DoxyCompactList}\small\item\em Return aerosol mass given a volume, based on aerosol size distribution function. \end{DoxyCompactList}\item
real(kind=wp) function \hyperlink{classm__aerosol_a2dff4ff413057e8788fba7270a30c093}{lamsed} (V\-O\-L, H, M\-U\-G, R\-H\-O\-A\-E\-R, A\-G\-A\-M\-M\-A, A\-C\-H\-I, A\-F\-E\-O, K\-O, M\-A\-E\-R, F\-M\-A\-E\-R, F\-A\-E\-R\-S\-S, F\-S\-E\-D\-D\-K)
\begin{DoxyCompactList}\small\item\em Calculate aerosol removal constant and interpolation factor between steady-\/state and decaying aerosol correlations. \end{DoxyCompactList}\item
pure real(kind=wp) function \hyperlink{classm__aerosol_a6d0a04004f49c404c67e0aa69dd39ee1}{fdbend} (V\-E\-L, H\-S\-E\-D, T\-G, R\-H\-O\-G, M\-U\-G, R\-H\-O\-P\-A\-R, C\-A\-E\-R\-O, X\-D\-B\-E\-N\-D, N90\-J)
\begin{DoxyCompactList}\small\item\em Find total impaction efficiency for aerosol deposition considering 90-\/degree bends in a flow path. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Public Attributes}
\begin{DoxyCompactItemize}
\item
integer, parameter \hyperlink{classm__aerosol_a8f604b7ffe3c1833ffa6f2fae54ededb}{ia\-\_\-nsize} = 30
\item
integer, parameter \hyperlink{classm__aerosol_ae71813ecf0c7768af9d6292efb14774f}{ia\-\_\-nmass} = 10
\item
real(kind=wp), dimension(\hyperlink{classm__aerosol_a8f604b7ffe3c1833ffa6f2fae54ededb}{ia\-\_\-nsize}), \\*
Nothing obviously matches the recently read chunk "\LT#LL#FM#cr" and I don't know enough low-level TeX to translate that into something that might actually be in the source text.
Suspecting this might have been fixed in a later version of Doxygen than the one shipping with Linux Mint (v1.8.1.2), I built & installed v1.8.3.1 from source, updated my doxyfile, blew away the old documentation and regenerated it. I get the same baffling error.
There's nothing obvious in refman.log that would indicate missing or broken LaTeX packages and I'm completely at a loss as to what's causing this.
As this still gets a hit on Google when you search:
doxygen missing $ inserted
I would like to add something.
Do not use a PROJECT_NAME containing underscores (_)!
After a brief look into the doxygen's current documentation (I am using 1.8.4) it does not make that explicit.
this will be difficult to solve unless you provide a bit more information - possibly using \errorcontextlines=9999 as suggested in the comments on the question.
as a first short though, the name of the control sequence that can't be found (i.e. \LT#LL#FM#cr) is one defined by the longtable package (documentation, p. 15) - thus adding:
\usepackage{longtable}
to the preamble of the document might help.
If so, according to the doxygen documentation here, adding the following to your configuration file should do the trick:
EXTRA_PACKAGES=longtable
I would like to create a Sublime Text 2 Snippet that fills up the space before and after the Variable I type with spaces.
It should look like this:
===========================my_filename.js===========================
The Filename should be centered so the number of spaces before and after the Text have to match.
Also I need the overall column width of this line the stay the same. So when I add 2 Characters the number of spaces on each side gets reduced by one.
I think a sample for this would be:
spacesLeft = roundDown((columnWidth/2) - (textSize/2))
spacesRight = roundUp((columnWidth/2) - (textSize/2))
But since only RegEx is available in Sublime Snippets I don't see me able, to accomplish this task.
Could Vintagmode help me in any Way?
Thanks for your help!
Because snippets are essentially static, they wouldn't be able to help you in this case. However, you could create a plugin to do this relatively easily. Sublime Text uses python for its plugins. You can create one by going to Tools > New Plugin. ST2's API can be found here and is very impressive. Essentially, you'll want to store the current selection (your variable) using
sel_reg = self.view.sel()[0] # the current selection 'Region'
sel = self.view.substr(sel_reg) # the text within the 'Region'
Then generate the ='s
signs = ''
each_side = len(80 - len(sel))/2 # 80 is the standard window length,
# change this to what you want.
# Not sure about how to make it dynamic.
for x in xrange(each_side):
signs += '='
Then replace the current line (self.view.line(sel)) with signs + sel + signs.
I wonder if there is any way to invert the way the LaTeX interprets linebreaks in equations? E.g., I dont want to insert them explicitly like,
\begin{gather}
x = y \\
a = c
\end{gather}
, but implicitly like,
\begin{gather}
x = y
a = c
\end{gather}
Thanks.
This is against the intention of TeX’s author, who believed that math must be typeset by hand. I tried obeylines, but to no avail. I guess it’s possible by making new line active, but you should ask the cracks over at Stack Exchange, a branch of Stack Overflow for TeX and LaTeX.
The breqn package will automatically insert linebreaks in equations when the line is full. I don't know of anything that will do break as you ask. If it is a big deal you could use perltex to define a macro that would do it for you. I will try to mock one up as an example.
I'm currently searching for an application or a script that does a correct word count for a LaTeX document.
Up till now, I have only encountered scripts that only work on a single file but what I want is a script that can safely ignore LaTeX keywords and also traverse linked files...ie follow \include and \input links to produce a correct word-count for the whole document.
With vim, I currently use ggVGg CTRL+G but obviously that shows the count for the current file and does not ignore LaTeX keywords.
Does anyone know of any script (or application) that can do this job?
I use texcount. The webpage has a Perl script to download (and a manual).
It will include tex files that are included (\input or \include) in the document (see -inc), supports macros, and has many other nice features.
When following included files you will get detail about each separate file as well as a total. For example here is the total output for a 12 page document of mine:
TOTAL COUNT
Files: 20
Words in text: 4188
Words in headers: 26
Words in float captions: 404
Number of headers: 12
Number of floats: 7
Number of math inlines: 85
Number of math displayed: 19
If you're only interested in the total, use the -total argument.
I went with icio's comment and did a word-count on the pdf itself by piping the output of pdftotext to wc:
pdftotext file.pdf - | wc - w
latex file.tex
dvips -o - file.dvi | ps2ascii | wc -w
should give you a fairly accurate word count.
To add to #aioobe,
If you use pdflatex, just do
pdftops file.pdf
ps2ascii file.ps|wc -w
I compared this count to the count in Microsoft Word in a 1599 word document (according to Word). pdftotext produced a text with 1700+ words. texcount did not include the references and produced 1088 words. ps2ascii returned 1603 words. 4 more than in Word.
I say that's a pretty good count. I am not sure where's the 4 word difference, though. :)
In Texmaker interface you can get the word count by right clicking in the PDF preview:
Overleaf has a word count feature:
Overleaf v2:
Overleaf v1:
I use the following VIM script:
function! WC()
let filename = expand("%")
let cmd = "detex " . filename . " | wc -w | perl -pe 'chomp; s/ +//;'"
let result = system(cmd)
echo result . " words"
endfunction
… but it doesn’t follow links. This would basically entail parsing the TeX file to get all linked files, wouldn’t it?
The advantage over the other answers is that it doesn’t have to produce an output file (PDF or PS) to compute the word count so it’s potentially (depending on usage) much more efficient.
Although icio’s comment is theoretically correct, I found that the above method gives quite accurate estimates for the number of words. For most texts, it’s well within the 5% margin that is used in many assignments.
If the use of a vim plugin suits you, the vimtex plugin has integrated the texcount tool quite nicely.
Here is an excerpt from their documentation:
:VimtexCountLetters Shows the number of letters/characters or words in
:VimtexCountWords the current project or in the selected region. The
count is created with `texcount` through a call on
the main project file similar to: >
texcount -nosub -sum [-letter] -merge -q -1 FILE
<
Note: Default arguments may be controlled with
|g:vimtex_texcount_custom_arg|.
Note: One may access the information through the
function `vimtex#misc#wordcount(opts)`, where
`opts` is a dictionary with the following
keys (defaults indicated): >
'range' : [1, line('$')]
'count_letters' : 0/1
'detailed' : 0
<
If `detailed` is 0, then it only returns the
total count. This makes it possible to use for
e.g. statusline functions. If the `opts` dict
is not passed, then the defaults are assumed.
*VimtexCountLetters!*
*VimtexCountWords!*
:VimtexCountLetters! Similar to |VimtexCountLetters|/|VimtexCountWords|, but
:VimtexCountWords! show separate reports for included files. I.e.
presents the result of: >
texcount -nosub -sum [-letter] -inc FILE
<
*VimtexImapsList*
*<plug>(vimtex-imaps-list)*
The nice part about this is how extensible it is. On top of counting the number of words in your current file, you can make a visual selection (say two or three paragraphs) and then only apply the command to your selection.
For a very basic article class document I just look at the number of matches for a regex to find words. I use Sublime Text, so this method may not work for you in a different editor, but I just hit Ctrl+F (Command+F on Mac) and then, with regex enabled, search for
(^|\s+|"|((h|f|te){)|\()\w+
which should ignore text declaring a floating environment or captions on figures as well as most kinds of basic equations and \usepackage declarations, while including quotations and parentheticals. It also counts footnotes and \emphasized text and will count \hyperref links as one word. It's not perfect, but it's typically accurate to within a few dozen words or so. You could refine it to work for you, but a script is probably a better solution, since LaTeX source code isn't a regular language. Just thought I'd throw this up here.