relative path to imported file in LaTeX - latex

I am currently reworking a set of slides to teach students at an university, of course the files are written in LaTeX. Too increase modularity, I want to include files relative to a base file, which will be imported by other files. So suppose I have the following structure:
|-- document.tex
`-- module
`-- a
|-- base.tex
`-- listings
`-- test.java
Now I want to import test.java inside base.java by referring to the relative path listings/test.java. Is there a way to then import base.tex into document.tex? Or can I at least extend the relative path listings/test.java to the new parent document document.tex, e.g. module/a/listings/test.java?
I am displaying listings by using minted which is unfortunately not affected by the import package.

I have figured it out.
To effectively recreate the secret principle of OOP you have to use the package currfile which has the \currfiledir command, which is like pwd in bash.
It only works in via \input or \include loaded files, not by using import or anything else. It also does not work with the fragile option activated.
In this manner, you may create a module, which is relative to it's base file, not the one your document starts in.

Related

Importing python packages within python packages (relative imports, __init__.py)

Let's say I have a directory like this
In main.py I have the code from main_package import func but I get an error saying
test/main_package/func.py", line 1, in <module>
from sub_package.aa import aaf1
ModuleNotFoundError: No module named 'sub_package'
The line from sub_pacakage.aa import aaf1 in main_package/func.py is causing the error. I can switch that line to an asbolute path (from main_package.sub_pacakage.aa import aaf1) and it works fine.
However, I want to not change the relative path to an absolute path.
I am assuming I have to modify main_package/__init__.py to achieve this but I am not sure how. How do I go about this?
I've tried adding from . import sub_package to main_package/__init__.py but it doesn't seem to be working.
The issue with absolute Python imports is that they are actually relative to any path defined in sys.path and also to your current working directory.
Thus, to make an import like from sub_package.aa work, you need to ensure that the parent folder of "sub_package" is in sys.path or is your current working directory.
The same goes for from main_package.sub_package.aa. You need to make sure that the parent folder of main_package is in sys.path or is your current working directory. So it makes a different how and from which directory you execute your Python code. You usually need to "cd" to the right directory first.
I've had similar problems in the past and thus I've created an experimental, new import library: ultraimport
It gives you more control over your import and lets you do file system based imports and therefore real relative imports. You could then write your func.py like this:
import ultraimport
# Given that aaf1 is defined in aa.py from your sub package
aaf1 = ultraimport('__dir__/subpackage/aa.py', 'aaf1')
This will always work, no matter what is your current working directory, what is your sys.path or how you run your code.

Changing the Gridpanel class in Gridworld

I am trying to follow the steps to change the Gridworld appearance according to this. I've already imported source code for my gridworld jar file; ie. I can go and look at Bug.class or Gridpanel.class if I wanted to. However, I can't edit these files to produce the results that that pdf suggests. How do I do this? Did I import the source code incorrectly?
I don't think you can edit an external resource like gridworld.jar. You are going to need to create 4 new packages:
actor
grid
gui
world
Then copy the class files from gridworld.jar packages into your corresponding ones. Now you can edit the files. Make sure you include any miscellaneous files that might also be in the gridworld.jar packages, their important.
With your own packages you no longer need the gridworld.jar external resource, and there is a difference in your import statements. Instead of
import gridworld.actor.Actor;
Do this:
import actor.Actor;
Note: You will need to change all of the import statements in the new package classes to reference the other new packages. I believe that there were also some errors, not project breaking, but I just added suppressors.

How to compress multiple folders into one archive?

I have some compression components (like KAZip, JVCL, zLib) and exactly know how to use them to compress files, but i want to compress multiple folders into one single archive and keep folders structure after extract, how can i do it?
in all those components i just can give a list of files to compress, i can not give struct of folders to extract, there is no way (or i couldn't find) to tell every file must be extracted where:
i have a file named myText.txt in folder FOLDER_A and have a file with same name myText.txt in folder FOLDER_B:
|
|__________ FOLDER_A
| |________ myText.txt
|
|__________ FOLDER_B
| |________ myText.txt
|
i can give a list of files to compress: myList(myText.txt, myText.txt) but i cant give the structure for uncompress files, what is best way to found which file belongs to which folder?
The zip format just does not have folders. Well, it kinda does, but they are kind of empty placeholders, only inserted if you need metadata storage like user access rights. But other than those rather rare advanced things - there is no need for folders at all. What is really done - and what you can observe opening zip file in the notepad and scrolling to the end - is that each file has its path in it, starting with "archive root". In your exanple the zip file should have two entries (two files):
FOLDER_A/myText.txt
FOLDER_B/myText.txt
Note, that the separators used are true slashes, common to UNIX world, not back-slashes used in DOS/Windows world. Some libraries would fix back-slashes it for you, some would not - just do your tests.
Now, let's assume that that tree is contained in D:\TEMP\Project - just for example.
D:\TEMP\Project\FOLDER_A\myText.txt
D:\TEMP\Project\FOLDER_B\myText.txt
There are two more questions (other than path separators): are there more folders within D:\TEMP\Project\ that should be ignored, rather than zipped (like maybe D:\TEMP\Project\FOLDER_C\*.* ? and does your zip-library have direct API to pack the folders wit hall its internal subfolder and files or should you do it file by file ?
Those three questions you should ask yourself and check while choosing the library. The code drafts would be somewhat different.
Now let's start drafting for the libraries themselves:
The default variant is just using Delphi itself.
Enumerate the files in the folder: http://docwiki.embarcadero.com/CodeExamples/XE3/en/DirectoriesAndFilesEnumeraion_(Delphi)
If that enumeration results in absolute paths then strip the common D:\TEMP\Project from the beginning: something like If AnsiStartsText('D:\TEMP\Project\', filename) then Delete(filename, 1, Length('D:\TEMP\Project\'));. You should get paths relative to chosen containing place. Especially if you do not compress the whole path and live some FOLDER_C out of archive.
Maybe you should also call StringReplace to change '\' into '/' on filenames
then you can zip them using http://docwiki.embarcadero.com/Libraries/XE2/en/System.Zip.TZipFile.Add - take care to specify correct relative ArchiveFileName like aforementioned FOLDER_A/myText.txt
You can use ZipMaster library. It is very VCL-bound and may cause troubles using threads or DLLs. But for simple applications it just works. http://www.delphizip.org/
Last version page have links to "setup" package which had both sources, help and demos. Among demos there is an full-featured archive browser, capable of storing folders. So, you just can read the code directly from it. http://www.delphizip.org/191/v191.html
You talked about JVCL, that means you already have Jedi CodeLib installed. And JCL comes with a proper class and function, that judging by name can directly do what you want it too: function TJclSevenzipCompressArchive.AddDirectory(const PackedName: WideString; const DirName: string = ''; RecurseIntoDir: Boolean = False; AddFilesInDir: Boolean = False): Integer;
Actually all those libraries are rather similar on basic level, when i made XLSX export i just made a uniform zipping API, that is used with no difference what an actual zipping engine is installed. But it works with in-memory TStream rather than on-disk files, so would not help you directly. But i just learned than apart of few quirks (like instant vs postponed zipping) on ground level all those libs works the same.

dartEditor file hierarchy and library/part logic

When I create a 'Web Application' with DartEditor in Windows8, it gives me this hierarchy
ClientView/
packages/
pubspec.lock
pubspec.yaml
web/
packages/
clientview.css
clientview.dart
clientview.dart.js
clientview.dart.js.deps
clientview.dart.js.map
clientview.html
I then add the lib/ file:
web/
...
lib/
src/
canvas.dart
i_drawable.dart
node.dart
client_canvas.dart
...
client_canvas.dart file
library client_view;
import 'dart:html';
import 'package:meta/meta.dart';
// Interface
part 'src/i_drawable.dart';
// Class
part 'src/canvas.dart';
part 'src/node.dart';
In each of the files included after the 'part' keyword, I've added this line:
part of client_view;
But it seems that none of the classes can be accessed by the other dart code
class Canvas implements IDrawable // no such type 'IDrawable'
abstract class Node implements IDrawable // no such type 'IDrawable'
class CustomNode extends Node // no such type 'Node' (if try to create a custom node)
I guess it's the way pubs and library are organized that I've not understood yet.
So what I tried to do is to create a library, inside the same project, I'd like to import that library inside the clientview.dart file that is called by the clientview.html file.
Your help would be greatly appreciated!
Since you're using relative imports, and everything appears to be part of the same library, I see no obvious reason for the errors. Maybe you can share some more details.
You should probably reorganize your source tree to be more inline with Pub standards though. web/ and lib/ should both be top level directories, otherwise you won't be able to do package: imports of your own libraries. This is one reason why it's recommended that web/ only contain entry points (scripts with a main() method) and everything else should be in lib/.
Also, I would try to use part very sparingly. I find it much better to define almost every file as a library and just import them. It makes dependencies for each file much more clear and allows consumers to only import the interfaces, and not the implementations. export makes it possible to build a library that exposes the definitions of another.
Finally, a style nit: Dart isn't C# and we don't use that ugly 'I' prefix on our interfaces :-) Just name your interface Drawable.

How to determine location of wrapper (relative to module - and not theme folder) in placement info file?

i am trying to specify a cshtml file as wrapper for specific ContentType in a placementinfo file.
my definition looks like this :
<Place Parts_Estate="Content:4;Wrapper=OrderResultItemWrapper"/>
now the problem is that , when i investigate the contentItem in ShapeTracing window i figured out that the search location for Wrapper view file is theme folder.
~/Themes/EmlakTheme/Views/OrderResultItemWrapper.cshtml
anyone have any idea how to convince the view engine to search within module folder rather than theme folder.
any help is very appreciated.
EDIT:
my problem is as follow :
1 - i have placed a cshtml file as a wrapper in the module's directory.
2 - i haven't placed any copy of (and not any other file with this name) in the theme folder
3 - the wrapper doesn't affect my shape.
4 - when i searched for problem i found out that shape tracing window showing the
"~/Themes/EmlakTheme/Views/OrderResultItemWrapper.cshtml"
path.that means it doesn't search the modules directory for my wrapper file and results in not displaying the wrapper.
EDIT
My problem have been solved.
my mistake was adding wrapper to DisplayTemplate directory.i have placed it in Views (root) directory and now it is working well.thanks all guys participating in answer.
If you have the same cshtml file in both a module and a theme, the latter will take precedence. If you need to use the one provided by module - delete the one from the theme.

Resources