Hot answers tagged

18

There are several weak points in this code. The main one is repeating setup and using explicit spacing in many places. Such code should be hidden in macros as much as possible. Here are some other points. the ucs package is not recommended utf8x should better be utf8 \usepackage{fontenc} does nothing at all \headsep=8mm is wrong syntax, better placed in ...


7

Not much to say about the last version; on the other hand, you could exploit PGF keys. \documentclass{article} \RequirePackage{xcolor} \RequirePackage{tikz} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % combine ducks % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \makeatletter %1: skin colour \...


7

While using sys.argv is fine for a first version of a program, you should give it a proper CLI. It would be nice if multiple latex files could be passed (since it is common to split a large project into multiple files) and also to specify the source and target languages. For this you can use argparse: import argparse def parse_args(args=None): parser = ...


6

To answer your questions in turn: Any package incompatibilities? Import ordering? Not that I can see, but you’re importing a lot of packages – 44 at a rough count. In general, I prefer to keep a small number of packages in my base file, and include them as-required. This reduces the likelihood of a package clash in a document (hyperref is one common ...


6

In my opinion, the code is reasonably clear. I would recomment couple changes to make it better: Externalize the C++ code; make it a separate file and load it from file using \inputminted. See the package documentation for details. Mark the ends of frames, it easies the navigation in the source code. I use this in my code: ... \end{frame} %%%%%%%%%%%%%%%%%...


6

So here are some points. Do ask if you need clarification: tikz loads pgf, so having \usepackage{pgf} is redundant. Personally I'd say only load the libraries you need. You may also use a single \usetikzlibrary, but that is I think just a matter of preference. The arrows.meta library has replaced arrows (the latter still works, but is considered deprecated, ...


6

There are some nice things about this script: It seems to work, you're using strict, and how you open your files is very good (you even consider encoding!). Unfortunately, it is extremely difficult to follow. Reasons for this are: This program has experienced “organic growth”. There are unnecessary print commands for debugging everywhere, and commented out ...


4

I spent a good time reading your code, only found minor stuff: You have code similar to this a few times: exec(command, options, function(err) { if (err) return next(err); return next(null); }); since you never check for the actual 'nullness' of err, you could just write return exec(command, options, next); I understand the following code is self ...


4

Always double-quote variables if they might contain spaces These commands will fail if the variables contain spaces: cd $FOLDER # ... echo >> $BIBTEX_FILE Even if you never intend to use your script with paths containing spaces, it's good to make it a habit to double-quote variables that might contain spaces: cd "$FOLDER" # ... echo >> "$...


4

You can do it in a more robust way, using expl3. \documentclass{article} \usepackage{xparse} \usepackage{mfirstuc} \ExplSyntaxOn \NewDocumentEnvironment{countwords}{+b} { % typeset the contents and add \par at the end #1 \par % save the contents of the environment in a token list variable \tl_set:Nn \l_tmpa_tl { #1 } % blank lines generate a \...


4

You can just start your loops from 1 to \w, instead of 0 and ending to \wMinusOne: just subtract 0.5, instead of adding it. Using \c for a color is not the best idea: properly define a color, here I used the name grid. Also the counter is not necessary, as there's a \foreach feature for it. I also put all \def inside tikzpicture and changed \char into \...


4

naming The naming convention is wrong. PEP-008 standardizes on snake_case for variables and functions, as the naming itself is unclear. What is rx? It is a repattern. Then call it so. adict is indeed a dict, but it contains the hashes, so also call it like that. map map is a useful tool, but not a lot of people use it or know it. Especially since the ...


4

About your points: The interface seems pretty clear. If you fear about the \arraystretch parameter being abused, you're right: on a double spaced document all tables come out horribly and local remedies are often necessary. Maybe adding a stretch key could help for these cases. Yes, you're abusing local and global assignments. Some comments about the code: ...


4

Argument checking You test that the user has specified exactly one input file, but if not, then print the misleading message Error loading file. You would be better with a usage message, such as std::cerr << "Usage: " << argv[0] << " filename" << std::endl; Well done for correctly using cerr for such messages. ...


4

The problem with inheriting from str in the cell is that it gives you much more unwanted options than you might want. Your Cell can be represented as a str, but it's not a str, which is the main idea behind inheritance. If we look at all the possible values of functions of str, I think we can see it's an overkill to inherit str. I think it'd be a better idea ...


3

I have a similar script. So from my experiences I would: build the pdfs through latexmk sometimes it needs more runs of pdflatex. I found it too hard to get right in plain make. have directories for work and artefacts. I don't like to have temporary files among my carefully written texts. The risk of an accidental rm or overwrite is just always present....


3

Nice. I mean if you're going for perfection I'm going to write something but otherwise that looks really good. The documentation for algorithm2e mentions that every line should be terminated with \; - and then has a flag to disable showing that semicolon, \DontPrintSemicolon - take that how you will. At least Emacs highlights that less garishly than the ...


3

Pattern match instead of using isJust and fromJust. (You could use maybe instead of pattern matching, but I think pattern matching is clearer in this case.) This eliminates the possibility of forgetting to ensure a value is a Just before calling fromJust on it. guessMetapost :: Options -> IO () guessMetapost opts = case optMetaPost opts of ...


3

Before rewriting the program, I'll start with some smaller issues. Minor simplifications Use print and '''long strings''' instead of multiple file.write() calls to get newlines. Use r'' (raw strings) to avoid doubling backslashes. I would just write the tables to standard output, and redirect the output to a file using the shell. That avoids hard-coding '...


3

You can use a recursive function with the pattern %b() as follows: function ToFrac( sInput ) local tStack = {} for sOperand in sInput:gmatch "%b()" do table.insert( tStack, sOperand:sub(2, -2) ) end while true do if #tStack <= 1 then break end local sNumerator = table.remove( tStack, 1 ) if sNumerator:find '...


3

When you are using packages, please make sure to say which ones. I guessed shellmate btw. As for the code, it's quite readable except for the handler definition which I've rewritten as follows: handler :: S.FilePath -> IO () handler f = do (Right isfile) <- S.shell $ S.isFile f if not isfile then putStrLn "File not found." else if ...


3

.substring() Note that .substring() values are not shared any more with the string they were created from (link). That means calls like body = body.substring(...).trim() will allocate two new strings: one for the .substring(...) and another for the .trim() which is another form of a sub-string. So if you are concerned about efficiency, avoid marching ...


3

Some minor comments: hyperref should be loaded after the other packages (there are only few exceptions, see https://tex.stackexchange.com/q/1863/36296) loading url is not really necessary because you already load hyperref you specify too many values of the geometry package. The paperheight is implicitly given by the default value of your tex distribution, ...


2

You have very large if code blocks that I can't help but wonder if it will be better to extract them as methods. For CombinedReader, maybe you can consider setting the StringReader to null when there is no more to be read from it: private static class CombinedReader { private StringReader stringReader; // this you can make final private final ...


2

I think you already have an idea about what to do. In particular, the idea to use a dictionary to store information using a key will make your code free of execs. For example: linesigs = {} for sig in stringsig: filename = 'SummerStc_{}_{}.txt'.format(stringcpu[1], sig) with open(filename, 'r') as filesig: linesigs[sig] = filesig.readlines() ...


2

The bar and foo targets (as well as the conditions on foo.uptodate and bar.uptodate) seems really similar to each other. I'd try to remove this duplication with a presetdef or a macrodef Reply for the edit: Nice to see that the macrodef works :-). A few other ideas: <attribute name="basename" default="unknown" /> Are you sure that you need the ...


2

I'm not a LaTex expert by any means, but I think I can help with this. First, it's important to step back and remember the original purpose for LaTeX. Quoting from https://www.latex-project.org/ LaTeX is not a word processor! Instead, LaTeX encourages authors not to worry too much about the appearance of their documents but to concentrate on getting the ...


2

A few minor comments: \RequirePackage{etoolbox} is not necessary with recent beamer versions, as this package is loaded automatically Instead of loading the subthemes with different options, depending of the value of your toggle, e.g. \iftoggle{light}{ \usecolortheme[light]{ibadai} }{% \usecolortheme{ibadai} } I'd prefer to directly pass the option to ...


2

It seems I needed Aristotle to save my project -- with the help of Saving Aristotle: How can Biblatex redefinitions be made conditional on the style selected? the code can me massively simplified to the following example: \documentclass{beamer} \usepackage[ % style=numeric, % style=numeric-comp, % style=numeric-verb, % style=authoryear, % style=...


1

Redefining \v and \i is a bad thing. Don't, you'll regret it as soon as you want to need to cite a paper by Eduard Čech or by Erdal Arıkan. You also have quite an inefficient usage of xstring and no error checking if a _ is forgotten. Here's a complete implementation with xparse: \documentclass{article} \usepackage{xparse} \NewDocumentCommand{\ind}{me{_}...


Only top voted, non community-wiki answers of a minimum length are eligible